Short copy from here:
exit(Pid, Reason) -> trueTypes:
Pid =
pid()
Reason =term()Sends an exit signal with exit reason
Reasonto the processPid.The following behavior apply if Reason is any term except
normalorkill:If
Pidis not trapping exits,Piditself will exit with exit reasonReason. IfPidis trapping exits, the exit signal is transformed into a message{'EXIT', From, Reason}and delivered to the message queue ofPid.Fromis the pid of the process which sent the exit signal. See alsoprocess_flag/2.If
Reasonis the atomnormal,Pidwill not exit. If it is trapping exits, the exit signal is transformed into a message{'EXIT', From, normal}and delivered to its message queue.If
Reasonis the atomkill, that is ifexit(Pid, kill)is called, an untrappable exit signal is sent toPidwhich will unconditionally exit with exit reasonkilled.
I am playing around with the exit/2 function and its behavior when self() is used as a Pid and normal as a Reason.
Erlang R15B03 (erts-5.9.3) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9.3 (abort with ^G)
1> self().
<0.32.0>
2> exit(self(), normal).
** exception exit: normal
3> self().
<0.35.0>
Shouldn’t it be the case that only a ‘normal’ exit message is sent to the shell process, so there is no reason to exit?
Similarly:
4> spawn(fun() -> receive Pid -> Pid ! ok end end).
<0.38.0>
5> exit(v(4), normal).
true
6> v(4) ! self().
<0.35.0>
7> flush().
Shell got ok
ok
But:
8> spawn(fun() -> exit(self(), normal), receive _ -> ok end end).
<0.43.0>
9> is_process_alive(v(8)).
false
As your third example shows if any process does an
exit(self(), normal)then it crashes while doingexit(AnotherPid, normal)does not crash the other process. I have verified it on an R15B. I personally think that this is a bug as sending exit signalnormalto any process should not result in its crashing.