[erlang-questions] propagation of exit signals among linked processes

Edmund Sumbar esumbar@REDACTED
Mon Jul 22 02:50:51 CEST 2013

Hi all,

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.

Here is the parent module (exits are being trapped).

-module (parent).
-export ([start/0, init/0]).

start() ->
spawn_link(parent, init, []).

init() ->
process_flag(trap_exit, true),
apply(child, start, []),

loop() ->
{'EXIT', Pid, _Reason} ->
io:format("Trapped exit pid ~p~n", [Pid]);
Other ->
io:format("Other ~p~n", [Other])

And here is the child. The child is started by the parent.

-module (child).
-export ([start/0, calc/1, loop/0]).

start() ->
register(child, spawn_link(child, loop, [])).

calc(Msg) ->
child ! {Msg, self()},
receive Result -> Result end.

loop() ->
{Msg, From} ->
>From ! Msg + 2,

When the child crashes, the system hangs. I have to interrupt the process
to restore the shell.

263> parent:start().
264> child:calc(a).
Trapped exit pid <0.621.0>

=ERROR REPORT==== 21-Jul-2013::15:11:03 ===
Error in process <0.621.0> with exit value:

User switch command
 --> i
 --> c
** exception exit: killed
265> i().

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.

260> child:calc(a).

=ERROR REPORT==== 21-Jul-2013::15:09:52 ===
Error in process <0.607.0> with exit value:

** exception exit: badarith
     in function  child:loop/0 (child.erl, line 14)

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130721/d9a6335c/attachment.htm>

More information about the erlang-questions mailing list