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

Bernard Duggan <>
Tue Dec 9 07:40:13 CET 2008


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



More information about the erlang-questions mailing list