[erlang-questions] propagation of exit signals among linked processes
Edmund Sumbar
esumbar@REDACTED
Mon Jul 22 07:18:32 CEST 2013
Oops, forgot to mention my Erlang version.
Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:8:8] [async-threads:10]
[hipe] [kernel-poll:false] [dtrace]
Eshell V5.10.1 (abort with ^G)
On Sun, Jul 21, 2013 at 6:50 PM, Edmund Sumbar <esumbar@REDACTED> wrote:
> 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().
>
> loop() ->
> receive
> {'EXIT', Pid, _Reason} ->
> io:format("Trapped exit pid ~p~n", [Pid]);
> %%loop();
> Other ->
> io:format("Other ~p~n", [Other])
> end.
>
> 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() ->
> receive
> {Msg, From} ->
> From ! Msg + 2,
> loop()
> end.
>
> When the child crashes, the system hangs. I have to interrupt the process
> to restore the shell.
>
> 263> parent:start().
> <0.620.0>
> 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:
> {badarith,[{child,loop,0,[{file,"child.erl"},{line,14}]}]}
>
>
> 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:
> {badarith,[{child,loop,0,[{file,"child.erl"},{line,14}]}]}
>
> ** exception exit: badarith
> in function child:loop/0 (child.erl, line 14)
> 261>
>
> 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/ef7ae561/attachment.htm>
More information about the erlang-questions
mailing list