有人可以在Erlang中解释一个Pid的结构吗? [英] Can someone explain the structure of a Pid in Erlang?

查看:399
本文介绍了有人可以在Erlang中解释一个Pid的结构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以在Erlang中解释Pid的结构吗?



Pids看起来像这样: < ABC> ,例如<0.30.0>,但我想知道这三个位的含义是什么:A,B和C。



'A'似乎在本地节点上始终为0,但是当Pid的所有者位于另一个节点上时,此值将更改。



是否可以在远程节点上直接发送消息只有Pid?这样的事情:< 4568.30.0>!消息,而不必明确地指定注册过程的名称和节点名称({proc_name,Node}!Message)?

解决方案

p>印刷过程ids< ABC>由 6




  • A,节点号(0是本地
    节点,远程节点的任意数字) li>
  • B,进程号的前15位(进程表中的索引) 7

  • C,进程号的位16-18(与B) 7



内部,32位仿真器的进程号是28位宽。 B和C的奇数定义来自于R9和Erlang的早期版本,其中B为15位进程ID,而当达到最大进程ID并且重新使用较低的ID时,C为换行计数器递增。



在erlang分布中,PID包含节点原子以及其他信息,有点大。 (分布式PID格式



当内部PID从一个节点发送到另一个节点时,它将自动转换为外部/分布式PID表单,因此可能是< 0.10.0> inet_db )可能会以$ code>< 2265.10.0> 结束。您可以正常发送到这些PID。

 %在OtherNode上获取用户服务器的PID 
RemoteUser = rpc:call(OtherNode,erlang,whereis,[user]),

true = is_pid(RemoteUser),

%发送消息到远程PID
RemoteUser! ignore_this,

%打印Hello from< nodename> \\\
在远程节点的控制台上。
io:format(RemoteUser,〜p〜n,[node()])。

有关更多信息,请参阅:内部PID结构
节点创建信息
节点创建计数器与EPMD的交互


Can someone explain the structure of a Pid in Erlang?

Pids looks like this : <A.B.C> , e.g. <0.30.0> , but i would like to know what is the meaning of these three "bits" : A, B and C.

'A' seems to be always 0 on a local node, but this value changes when the Pid's owner is located on another node.

Is it possible to directly send a message on a remote node using only the Pid ? Something like that : <4568.30.0> ! Message , without having to explicitely specify the name of the registered process and the node name ( {proc_name, Node} ! Message ) ?

解决方案

Printed process ids < A.B.C > are composed of 6:

  • A, the node number (0 is the local node, an arbitrary number for a remote node)
  • B, the first 15 bits of the process number (an index into the process table) 7
  • C, bits 16-18 of the process number (the same process number as B) 7

Internally, the process number is 28 bits wide on the 32 bit emulator. The odd definition of B and C comes from R9B and earlier versions of Erlang in which B was a 15bit process ID and C was a wrap counter incremented when the max process ID was reached and lower IDs were reused.

In the erlang distribution PIDs are a little larger as they include the node atom as well as the other information. (Distributed PID format)

When an internal PID is sent from one node to the other, it's automatically converted to the external/distributed PID form, so what might be <0.10.0> (inet_db) on one node might end up as <2265.10.0> when sent to another node. You can just send to these PIDs as normal.

% get the PID of the user server on OtherNode
RemoteUser = rpc:call(OtherNode, erlang,whereis,[user]), 

true = is_pid(RemoteUser),

% send message to remote PID
RemoteUser ! ignore_this, 

% print "Hello from <nodename>\n" on the remote node's console.
io:format(RemoteUser, "Hello from ~p~n", [node()]). 

For more information see: Internal PID structure, Node creation information, Node creation counter interaction with EPMD

这篇关于有人可以在Erlang中解释一个Pid的结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆