erlang中判断进程是否存活
一个参数的方法是已知Pid判断进程是否存活。两个参数的方法是已知节点和Pid或进程名判断进程是否存活。
is_process_alive(Pid) when is_pid(Pid) ->
rpc:call(node(Pid), erlang, is_process_alive, [Pid]);
is_process_alive(_Pid) ->
false.
is_process_alive(undefined, _ProcName) ->
false;
is_process_alive(_Node, undefined) ->
false;
is_process_alive(Node, Pid) when is_pid(Pid) ->
case rpc:call(Node, erlang, is_process_alive, [Pid]) of
undefined ->
false;
_Pid ->
true
end;
is_process_alive(Node, ProcName) ->
case rpc:call(Node, erlang, whereis, [ProcName]) of
undefined ->
false;
_Pid ->
true
end.