[erlang-questions] Sending a message to a process that no longer exists

Rapsey rapsey@REDACTED
Tue Dec 9 10:09:47 CET 2008


Or you can use a monitor (erlang:monitor/2), to receive a message when a
process dies.
Or you can check if a proces is alive with: erlang:is_process_alive(PID)


Sergej

On Tue, Dec 9, 2008 at 7:40 AM, Bernard Duggan <bernie@REDACTED> wrote:

> Jack Orenstein wrote:
> > On Dec 9, 2008, at 12:58 AM, Rapsey wrote:
> >
> >
> >> Using the send operator is very common. To avoid endless waiting in
> >> a receive statement you can use after:
> >>
> >> receive
> >>         {Server, Response} ->
> >>             ?DUMP({send_and_receive, received, Response}),
> >>             Response
> >>        after 1000 ->
> >>              void
> >>   end.
> >>
> >
> > But this won't distinguish a dead process from a slow one.
> >
> If you want to ensure the process is running, you can use
> process_flag(trap_exit, true),
> and then spawn_link(), instead of spawn() to create the server process.
> Then, in your receive block above add a pattern
>
> {'EXIT', Server, Reason}
>
> This will be sent to you when the server process exits for whatever reason.
>
> Cheers,
>
> Bernard
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081209/554cd7b5/attachment.htm>


More information about the erlang-questions mailing list