[erlang-questions] Adding simple process to supervisor?

Oscar Hellström <>
Thu Oct 9 22:43:43 CEST 2008


Hi Bengt,

What I usually do is just to spawn a reader process from the gen_server and link to it. Then depending on if the gen_server should die with errors in the reader process or not I sometimes traps exits in the gen_server. Most of the time you want to restart the gen_server to open a new socket if the reader dies anyway.  IMHO, there are too many issues with trying to get a process that does blocking calls to exist under a supervisor and this kind of process is typically very simple (read small room for errors) as well. Another approach is to use proc_lib to create a "special process" which uses {active, once} for the socket, to get away from doing blocking calls.

----- Original Message -----
From: "Bengt Kleberg" <>
To: "erlang-questions" <>
Sent: Thursday, 9 October, 2008 12:03:27 AM GMT -08:00 US/Canada Pacific
Subject: [erlang-questions] Adding simple process to supervisor?

Greetings,

I have a gen_server which is supervised according to OTP rules. Now I  
want to add a simple process that will read from a TCP port and send  
the incoming data to the gen_server. I could spawn_link this process  
from the gen_server and restart it if it dies. However, since I have a  
supervisor it seems more logical to just add the process there, as a  
rest_for_one.


There is the alternative of using a supervisor_bridge, but that seems  
more complex than using the gen_server. It seems as if I just design  
my process according to the OTP rules I will not need to use a  
supervisor_bridge. What are those rules? The only suggestions I have
found are:
1 Module:start_link/1 => {ok, Pid}
2 Module:terminate/2 => ok


The child specification returned by the init/1 call-back in a  
supervisor mentions the value for Modules if we have a gen_server,  
gen_fsm or gen_event. What could be used for a simple process?


But how do I add a simple process to the supervisor? It seems overkill
to masquerade it as a get_fsm or similar. Since it is not called from
erlang it is not a gen_server. Since it does not have state it is not a
gen_fsm. No events are handled.


bengt

_______________________________________________
erlang-questions mailing list

http://www.erlang.org/mailman/listinfo/erlang-questions

-- 
Oscar Hellström, 
Phone:  +44 (0)798 45 44 773
Mobile: +44 (0)207 65 50 337
Web:    http://www.erlang-consulting.com




More information about the erlang-questions mailing list