<div dir="ltr">Thanks @Joe, makes more sense.  <div><br></div><div>so as I read the process that creates the Socket is controlling process. When controlling process is killed, the Socket is closed. </div><div><br></div><div>My question is following</div><div><ol><li>How does killing of controlling process affect the process owned by Listen</li><li>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)?</li></ol><div><br></div></div><div>Thanks a lot</div><div>+ Harit Himanshu</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 27, 2015 at 10:48 AM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue, Jan 27, 2015 at 2:43 PM, Harit Himanshu<br>
<<a href="mailto:harit.subscriptions@gmail.com">harit.subscriptions@gmail.com</a>> wrote:<br>
> Hello<br>
><br>
> As I learn from Programming Erlang, the following is a way to create a<br>
> parallel server<br>
><br>
> start_parallel_server() -><br>
> {ok, Listen} = gen_tcp:listen(...), spawn(fun() -> par_connect(Listen) end).<br>
><br>
> par_connect(Listen) -><br>
> {ok, Socket} = gen_tcp:accept(Listen), spawn(fun() -> par_connect(Listen)<br>
> end), loop(Socket).<br>
><br>
><br>
> I wanted to dissect this code to understand what's going on.<br>
><br>
> Questions<br>
><br>
> When we call start_parallel_server()  on a single machine, a separate<br>
> process is started (which is controlling process?) executing par_connect,<br>
> correct?<br>
> When gen_tcp:accept accepts a new connection, immediately a new process is<br>
> created executing par_connect(Listen). This makes sure that we can accept<br>
> more requests from the client. Now who is the controlling process for this<br>
> new process? is the same as Listen?<br>
<br>
</div></div>no<br>
<br>
Listen is owned by the process that called gen_tcp:listen<br>
Socket is owned by the process that called gen_tcp:accept<br>
<br>
So you end up with one Listen process and N different values of<br>
Socket (one per spawned process). Each parallel process has it's own socket<br>
<br>
/Joe<br>
<br>
<br>
><br>
><br>
> Thanks<br>
> + Harit Himanshu<br>
><br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
</blockquote></div><br></div>