[erlang-questions] Issue in killing the process

Raimo Niskanen raimo+erlang-questions@REDACTED
Tue Oct 9 14:54:27 CEST 2018


On Tue, Oct 09, 2018 at 07:21:38PM +0900, zxq9@REDACTED wrote:
> On 2018年10月9日火曜日 10時18分20秒 JST Prakash Parmar wrote:
> > As mentioned in exit/2<http://erlang.org/doc/man/erlang.html#exit-2> doc,
> > 
> > 
> >  "... If Reason is the atom normal, Pid does not exit. If it is trapping exits, the exit signal is transformed into a message {'EXIT', From, normal} and delivered to its message queue. ..."
> > 
> > 
> > use exit(whereis(Pid), Reason), where Reason will be anything than normal .
> 
> Indeed. Nice catch. I didn't even address the case where the process is trapping exits.
> 
> Like the old Raid commercial: "A call to `exit(Pid, kill)` kills bugs dead."
> 
> -Craig

Do remember that all signals (and messages) are asynchronous, so if you
send exit(Pid, kill) the process Pid will eventually cease to exist,
albeit probably sooner than with exit(Pid, die).

To be certain that the target process no longer exists you need to monitor
its state:

    Mref = erlang:monitor(process, Pid),
    exit(Pid, die),
    receive {'DOWN',Mref,_,_,_} -> ok end,

There you have a synchronous exit, which at least in theory also should be
used for reason 'kill'...  After this you can e.g spawn a new process that
registers the same name.
This is equivalent to what the supervisors and such does.

Regards
-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list