[erlang-questions] Strange behaviour of exit(kill)

Robert Virding <>
Wed Oct 7 03:00:10 CEST 2015


I am giving an Erlang course and we are looking at the error handling. When
showing examples I found a very strange behaviour (to me) of doing
exit(kill). The linked process gets the 'kill' but it is trappable.
However, if I use exit(P, kill) to send the kill signal it is, as it should
be, not trappable.

Erlang/OTP 18 [erts-7.0] [source-4d83b58] [64-bit] [smp:8:8]
[async-threads:10] [hipe] [kernel-poll:false]

Eshell V7.0  (abort with ^G)
1> process_flag(trap_exit, true).
false
2> spawn_link(fun () -> exit(normal) end).
<0.36.0>
3> flush().
Shell got {'EXIT',<0.36.0>,normal}
ok
4> spawn_link(fun () -> exit(die) end).
<0.39.0>
5> flush().
Shell got {'EXIT',<0.39.0>,die}
ok
6> S = self().
<0.33.0>
7> spawn_link(fun () -> exit(S, die) end).
<0.43.0>
8> flush().
Shell got {'EXIT',<0.43.0>,die}
Shell got {'EXIT',<0.43.0>,normal}
ok
9> spawn_link(fun () -> exit(kill) end).
<0.46.0>
10> flush().
Shell got {'EXIT',<0.46.0>,kill}
ok
11> spawn_link(fun () -> exit(S, kill) end).
** exception exit: killed

The shell evaluator process traps exits and then spawn_links a number of
processes which exit/1 and exit/2 with different reasons. Everything
behaves normally until 9> where I spawn_link a process which does an
exit(kill). I get the 'kill' signal, but it is a trappable 'kill' signal!
If I send the 'kill' signal with exit/2 it is not trappable, as it
shouldn't be.

What gives? So just receiving a 'kill' signal is not what kills me but it
has to be sent in a certain way. So the process receiving a signal knows
how the signal was sent. This is really inconsistent! It should be the
signal itself which determines what the receiving process does. I would
definitely class this as a bug.

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151006/d1872236/attachment.html>


More information about the erlang-questions mailing list