[erlang-questions] Question on building a Parallel Server

Harit Himanshu harit.subscriptions@REDACTED
Sun Feb 8 05:52:46 CET 2015


Thanks @Joe, makes more sense.

so as I read the process that creates the Socket is controlling process.
When controlling process is killed, the Socket is closed.

My question is following

   1. How does killing of controlling process affect the process owned by
   Listen
   2. If we reverse this approach, how does killing of process (which owns
   Listen) affects n controlling processes (for n different Sockets associated
   with this Listen process)?


Thanks a lot
+ Harit Himanshu

On Tue, Jan 27, 2015 at 10:48 AM, Joe Armstrong <erlang@REDACTED> wrote:

> On Tue, Jan 27, 2015 at 2:43 PM, Harit Himanshu
> <harit.subscriptions@REDACTED> wrote:
> > Hello
> >
> > As I learn from Programming Erlang, the following is a way to create a
> > parallel server
> >
> > start_parallel_server() ->
> > {ok, Listen} = gen_tcp:listen(...), spawn(fun() -> par_connect(Listen)
> end).
> >
> > par_connect(Listen) ->
> > {ok, Socket} = gen_tcp:accept(Listen), spawn(fun() -> par_connect(Listen)
> > end), loop(Socket).
> >
> >
> > I wanted to dissect this code to understand what's going on.
> >
> > Questions
> >
> > When we call start_parallel_server()  on a single machine, a separate
> > process is started (which is controlling process?) executing par_connect,
> > correct?
> > When gen_tcp:accept accepts a new connection, immediately a new process
> is
> > created executing par_connect(Listen). This makes sure that we can accept
> > more requests from the client. Now who is the controlling process for
> this
> > new process? is the same as Listen?
>
> no
>
> Listen is owned by the process that called gen_tcp:listen
> Socket is owned by the process that called gen_tcp:accept
>
> So you end up with one Listen process and N different values of
> Socket (one per spawned process). Each parallel process has it's own socket
>
> /Joe
>
>
> >
> >
> > Thanks
> > + Harit Himanshu
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150207/c5f30dbc/attachment.htm>


More information about the erlang-questions mailing list