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

Soup <>
Wed Oct 7 03:20:13 CEST 2015


At 9, the spawned process is killing itself with reason kill, and the shell
received a trappable exit message. At 11, the spawned process is killing
the *shell* with reason kill. That's not a trappable signal coming from
another process: it's an emulator command to kill the specified process,
and the reason kill makes it untrappable.

It's a little nuanced, but pretty straightforward otherwise. When a process
dies, it informs linked processes by way of message, which forces exit
unless the receiving process is trapping exits. *exit/2 does not produce a
message*, it tries to terminate the process. It's only converted into a
message if the process is trapping exits, and reason kill bypasses the
trapping logic.
On Oct 6, 2015 9:00 PM, "Robert Virding" <> wrote:

> 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
>
>
> _______________________________________________
> erlang-bugs mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-bugs
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151006/1868a013/attachment.html>


More information about the erlang-questions mailing list