[erlang-questions] exit (kill) vs. exit(PID,kill)

Fred Hebert mononcqc@REDACTED
Tue Mar 6 21:30:49 CET 2012


exit/1 and exit/2 are wildly different things. exit/1 is a local thing,
much like erlang:error/1 and throw/1. They interact with the current stack,
and you catch them with either 'catch' or 'try ... catch'.

exit/2 on the other hand, sends 'exit signls' to other processes. They
can't be caught, unless you use trap_exit. In these cases, trap_exit can
make a process basically unkillable, so a special one ('kill') exists that
bypasses the issue.

When your process dies of reason 'kill' (either because I called exit(kill)
or exit(self(), kill)), the reason is changed to 'killed' to avoid
cascading failures of linked processes that trap exits, and the signal
received is in fact 'killed', similar to 'exit(Pid, killed)' in some ways,
although they operate differently.

Hopefully this makes it a bit clearer. I've got more complete explanations
at http://learnyousomeerlang.com/errors-and-processes, but it's a lengthy
read for the question.

On Tue, Mar 6, 2012 at 2:18 PM, Shahrdad Shadab <shahrdad1@REDACTED> wrote:

> I am amazed by difference between the effects of exit (kill) and exit
> (PID,kill).
>
> Assume PA and PB are two processes and PA has its trap_exit set to true.
> When PB evaluates exit(kill), the process terminates but PA doesn't die
> and actually gets message {EXIT,PB,kill}.
> However When PB evaluates exit(PA,kill), PA dies right a way !
>
> Will someone please explain the intention behind this behavior? (or I am
> missing something!
>
> Thanks a lot
>
> --
> Software Architect & Computer Scientist
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120306/9492e7ff/attachment.htm>


More information about the erlang-questions mailing list