<p>When you run child:calc/1 it sends a message to the child, and immediately after that shell process executes second line of child:calc/1, which is message receive. Shell hangs, since it waits for a message which never arrives. If you are doing a request to a process which might crash before responding , monitor that process temporarily starting before sending the message and demonitoring after response is received - in case child dies you will get 'DOWN' message.</p>

<p>HTH,<br>
Gleb Peregud</p>
<p>Sent from mobile, sorry for typos.</p>
<div class="gmail_quote">22 lip 2013 08:21, "Edmund Sumbar" <<a href="mailto:esumbar@gmail.com">esumbar@gmail.com</a>> napisał(a):<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Oops, forgot to mention my Erlang version.<div><br></div><div><div>Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]</div><div><br></div><div>Eshell V5.10.1  (abort with ^G)</div>

</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jul 21, 2013 at 6:50 PM, Edmund Sumbar <span dir="ltr"><<a href="mailto:esumbar@gmail.com" target="_blank">esumbar@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 dir="ltr">Hi all,<div><br></div><div>I'm still new to Erlang and am having difficulty understanding why the system (or shell) hangs when a process at the end of a chain of linked processes crashes.</div>

<div>
<br></div><div>Here is the parent module (exits are being trapped).</div><div><br></div><div><div>-module (parent).</div><div>-export ([start/0, init/0]).</div><div><br></div><div>start() -></div><div>
<span style="white-space:pre-wrap">     </span>spawn_link(parent, init, []).</div><div><br></div><div>init() -></div><div><span style="white-space:pre-wrap">        </span>process_flag(trap_exit, true),</div><div><span style="white-space:pre-wrap">   </span>apply(child, start, []),</div>


<div><span style="white-space:pre-wrap">  </span>loop().</div><div><br></div><div>loop() -></div><div><span style="white-space:pre-wrap">      </span>receive</div><div><span style="white-space:pre-wrap">          </span>{'EXIT', Pid, _Reason} -></div>


<div><span style="white-space:pre-wrap">                  </span>io:format("Trapped exit pid ~p~n", [Pid]);</div><div><span style="white-space:pre-wrap">                     </span>%%loop();</div><div><span style="white-space:pre-wrap">                </span>Other -></div>


<div><span style="white-space:pre-wrap">                  </span>io:format("Other ~p~n", [Other])</div><div><span style="white-space:pre-wrap">       </span>end.</div><div><br></div><div>And here is the child. The child is started by the parent.</div>


<div><br></div><div><div>-module (child).</div><div>-export ([start/0, calc/1, loop/0]).</div><div><br></div><div>start() -></div><div><span style="white-space:pre-wrap">       </span>register(child, spawn_link(child, loop, [])).</div>


<div><br></div><div>calc(Msg) -></div><div><span style="white-space:pre-wrap">   </span>child ! {Msg, self()},</div><div><span style="white-space:pre-wrap">   </span>receive Result -> Result end.</div><div><br></div>
<div>loop() -></div><div><span style="white-space:pre-wrap">       </span>receive</div><div><span style="white-space:pre-wrap">          </span>{Msg, From} -></div><div><span style="white-space:pre-wrap">                        </span>From ! Msg + 2,</div>


<div><span style="white-space:pre-wrap">                  </span>loop()</div><div><span style="white-space:pre-wrap">   </span>end.</div><div><br></div><div>When the child crashes, the system hangs. I have to interrupt the process to restore the shell.</div>


<div><br></div><div><div>263> parent:start().</div><div><0.620.0></div><div>264> child:calc(a).</div><div>Trapped exit pid <0.621.0></div><div><br></div><div>=ERROR REPORT==== 21-Jul-2013::15:11:03 ===</div>


<div>Error in process <0.621.0> with exit value: {badarith,[{child,loop,0,[{file,"child.erl"},{line,14}]}]}</div><div><br></div><div><br></div><div>User switch command</div><div> --> i</div><div> --> c</div>


<div>** exception exit: killed</div><div>265> i().</div><div><br></div><div>On the other hand, if the parent code is altered to not trap exits, the crash takes down the child, parent, and shell, but the system does not hang. I immediately end up with a new shell process.</div>


<div><br></div><div><div>260> child:calc(a).</div><div><br></div><div>=ERROR REPORT==== 21-Jul-2013::15:09:52 ===</div><div>Error in process <0.607.0> with exit value: {badarith,[{child,loop,0,[{file,"child.erl"},{line,14}]}]}</div>


<div><br></div><div>** exception exit: badarith</div><div>     in function  child:loop/0 (child.erl, line 14)</div><div>261> </div><div><br></div><div>Sorry for the rookie question, but I just can not figure it out. Can someone explain this behaviour or point me to some documentation. Thanks.</div>


</div></div></div></div></div>
</blockquote></div><br></div>
<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>