Determining if process is alive on a different node

Rick Pettit rpettit@REDACTED
Mon Aug 15 21:52:15 CEST 2005

On Mon, Aug 15, 2005 at 09:21:59PM +0200, Joel Reymont wrote:
> Serge's use of use of node(Pid) made me thing that the following  
> would work:
> rcp:call(node(pid), erlang, is_process_alive, [Pid]).
> Any drawbacks?
>     Thanks, Joel

Wouldn't wrapping the operation in a erlang:monitor/2, erlang:demonitor/1 with
a receive following the operation (to catch the potential 'DOWN' message) be

do_it(Pid) ->
  MonitorRef = erlang:monitor(process, Pid),
  ...perform operation to obtain Result here...
  receive {'DOWN', MonitorRef, process, Pid, Info} -> {error, Info}
    after 0 -> {ok, Result}

I should add that the call to erlang:monitor/2 will fail with 'badarg' on
"old" nodes where remote process monitoring is not implemented, at least
according to the manpage.
Without wrapping the operation this way it would seem as though there is always
a race between when you check to see if the process is alive and when you
conduct your operation with the process.


> On Aug 15, 2005, at 9:06 PM, Serge Aleynikov wrote:
> >node(Pid) returns the node that owns the Pid.
> >
> >Node = node(),
> >case node(Pid) of
> >Node -> local;
> >_    -> remote
> >end.

More information about the erlang-questions mailing list