Determining if process is alive on a different node
Serge Aleynikov
serge@REDACTED
Mon Aug 15 21:51:55 CEST 2005
Joel,
Sorry, after rereading your message I realized I responded too quickly. :-(
Yes the
rpc:call(node(Pid), erlang, is_process_alive, [Pid]) would be the
logical way to do it, but is it reliable?
What if the node(Pid) node got bounced since the time we captured the
Pid. The Pid value might've been reassigned to another process, as in
the example below:
(a@REDACTED)18> register(test, self()).
true
(b@REDACTED)1> net_adm:ping(a@REDACTED).
pong
(b@REDACTED)2> {test, a@REDACTED} ! self().
<0.36.0>
(a@REDACTED)2> receive M -> M end.
<4771.36.0>
(b@REDACTED)3> ^C
BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
(v)ersion (k)ill (D)b-tables (d)istribution
a
~/tmp>erl -sname b
Erlang (BEAM) emulator version 5.4.8 [source] [hipe] [threads:0]
Eshell V5.4.8 (abort with ^G)
(b@REDACTED)1> net_adm:ping(a@REDACTED).
pong
(a@REDACTED)5> rpc:call(b@REDACTED, erlang, is_process_alive,
[pid(4771,36,0)]).
true
--------------
This last statement is not true, since it is not the same process on
node b that originated the first message. The Pid that was originally
recorded was reassigned to another process after the node was bounced.
I believe it is more reliable to use erlang:monitor/2 calls at a time
the Pid is captured, and watch for {'DOWN', ...} messages.
Regards,
Serge
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
>
> 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.
>
>
>
--
Serge Aleynikov
R&D Telecom, IDT Corp.
Tel: (973) 438-3436
Fax: (973) 438-1464
serge@REDACTED
More information about the erlang-questions
mailing list