[erlang-questions] Exit signals are funny things

Robert Virding rvirding@REDACTED
Fri May 5 14:05:38 CEST 2017


There is more. So:

1> process_flag(trap_exit, true).
false
2> Pid = spawn_link(fun() -> process_flag(trap_exit,true),
timer:sleep(infinity) end).
<0.60.0>

We trap exits and spawn_link which also traps exits and just hangs there
waiting.

3> spawn(fun() -> link(Pid), exit(kill) end).
<0.62.0>
4> process_info(Pid, messages).
{messages,[{'EXIT',<0.62.0>,kill}]}

Now we spawn a new process which links to our hanger and exits with the
reason 'kill'. We can then check our hanger and see that it received a
'kill' signal which it converted to a message because it was trapping.
Finally:

5> spawn(fun() -> exit(Pid, kill) end).
<0.65.0>
6> flush().
Shell got {'EXIT',<0.60.0>,killed}
ok

we spawn another process which uses exit/2 to send a 'kill' signal to our
hanger and in this case it cannot trap the signal and dies with the reason
'killed'. So there is 'kill' and 'kill' depending on how I send it.

Where's the logic in that?

Robert

P.S. Yes, I know that getting a 'killed' from a process which has been
killed with a 'kill' signal is the correct.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170505/79915641/attachment.htm>


More information about the erlang-questions mailing list