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

Gleb Peregud gleber.p@REDACTED
Mon Jul 22 08:36:01 CEST 2013


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.

HTH,
Gleb Peregud

Sent from mobile, sorry for typos.
22 lip 2013 08:21, "Edmund Sumbar" <esumbar@REDACTED> napisał(a):

> 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.
>>
>
>
> _______________________________________________
> 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/20130722/c54e60c9/attachment.htm>


More information about the erlang-questions mailing list