[erlang-questions] Looking for examples of interaction between gen_server and gen_fsm

Christian Czura <>
Thu Aug 28 09:46:27 CEST 2008

it's a little bit hard for me to grasp how to plug together gen_servers
and gen_fsms that belong to the same service or operation.

For example, Joe shows[1] how to abstract away the protocol of a
webserver, so you end up having three processes[2]:
server <-> some_protocol <-> tcp/udp
I would write the server-process as a gen_server and the
protocol-process as a gen_fsm.

Now I wonder how/where to start the protocol-process from the server:
Would I start it from the server's init function and save its pid in the
server's state?

Or would I start both the server and the protocol-process via the
supervisor / supervision strategy?
If so, how does the server know about the protocol-process? It's obvious
that the protocol-process's pid needs to be passed along somehow to the

You might have noticed that I'm not sure when to use a supervision
strategy or when to spawn a process from within a process that is
supervised. That is because I don't know how/if it's possible in a
supervision strategy to pass along the pid of one process to another.
{M,F,A} in the childspec comes to mind, but how do I get the pid of
another process in the same childspec, and is this the right way of
doing things?

If you know any other helpful code example, feel free to post the link. :-)

[1]: http://www.sics.se/~joe/tutorials/web_server/web_server.html
[2]: http://www.sics.se/~joe/tutorials/web_server/web_server.jpg


More information about the erlang-questions mailing list