[erlang-questions] Why is the spawn_link not working?

Alexandre Beaulne alexandre.beaulne@REDACTED
Mon Jan 13 01:50:31 CET 2014


To add to Bob's answer:

>From the documentation<http://www.erlang.org/doc/reference_manual/processes.html#id83186>
:



*The default behaviour when a process receives an exit signal with an exit
reason other than normal, is to terminate and in turn emit exit signals
with the same exit reason to its linked processes. An exit signal with
reason normal is ignored. A process can be set to trap exit signals by
calling:*

process_flag(trap_exit, true)



*When a process is trapping exits, it will not terminate when an exit
signal is received. Instead, the signal is transformed into a message
{'EXIT',FromPid,Reason} which is put into the mailbox of the process just
like a regular message. An exception to the above is if the exit reason is
kill, that is if exit(Pid,kill) has been called. This will unconditionally
terminate the process, regardless of if it is trapping exit signals or not.*

Usually the trap_exit flag is set in the initialization function of a
process, which you could add to your drop.erl module:

init() ->
    process_flag(trap_exit, true),
    drop().

and spawn the drop process with spawn_link(drop, init, []) instead of
spawn_link(drop, drop, []).

Note that as few processes as possible should trap exit
signals.<http://www.erlang.se/doc/programming_rules.shtml#HDR22>


On Mon, Jan 13, 2014 at 8:36 AM, Yves S. Garret
<yoursurrogategod@REDACTED>wrote:

> Hello,
>
> I've recently created the following two modules from a book:
> http://bin.cakephp.org/view/1356260281
> http://bin.cakephp.org/view/13533081
>
> Now, when I send Pid ! {moon, asdf}. I get the following output:
> 39> Pid ! {moon, w}.
> Received the input and sending now.
> Received the input to drop.
> {moon,w}
>
> =ERROR REPORT==== 12-Jan-2014::19:31:38 ===
> Error in process <0.162.0> with exit value:
> {badarith,[{drop,fall_velocity,2,[{file,"drop.erl"},{line,27}]},{drop,drop,0,[{file,"drop.erl"},{line,17}]}]}
>
> Why am I not seeing this line run?
> io:format("FAILURE: ~p died because of ~p.~n~n", [Pid, Reason]);
>
> _______________________________________________
> 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/20140113/3f05399f/attachment.htm>


More information about the erlang-questions mailing list