[英]How to get in erlang the pid of a node name?
我有一個節點: app01@mdiaz ,我需要知道 pid(類似於<2908.77.0> )
Erlang 節點沒有一個單獨的 pid:每個節點上運行着許多進程,因此您需要指定所需的進程。
如果您想知道在節點bar@localhost
上以名稱foo
注冊的進程的 pid,您可以對erlang:whereis/1
進行 RPC 調用:
(foo@localhost)1> rpc:call(bar@localhost, erlang, whereis, [foo]).
<7120.56.0>
雖然您可能不需要它:如果您想向另一個節點上的命名進程發送消息,您可以使用{Name, Node}
而不是首先獲取 pid。 例如,要向bar@localhost
上名為foo
的進程發送消息:
{foo, bar@localhost} ! my_message
您還可以使用node/1
函數從 pid 中獲取節點名稱:
(foo@localhost)1> RemotePid = rpc:call(bar@localhost, erlang, whereis, [foo]).
<6928.32.0>
(foo@localhost)2> node(RemotePid).
bar@localhost
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.