有人可以用Erlang解释Pid(进程标识符)的结构吗? [英] Can someone explain the structure of a Pid (Process Identifier) in Erlang?

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

问题描述

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

Can someone explain the structure of a Pid in Erlang?

ID如下所示: <A.B.C> ,例如< 0.30.0>,但是我想知道这三个位"(A,B和C)的含义.

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"在本地节点上似乎始终为0,但是当Pid的所有者位于另一个节点上时,此值会更改.

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

是否可以仅使用Pid在远程节点上直接发送消息?那样的东西:< 4568.30.0>! Message,而不必显式指定注册进程的名称和节点名称({proc_name,Node}!Message)?

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 ) ?

推荐答案

打印的进程ID< ABC>由 6 :

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

  • A,节点号(0是本地 节点,远程节点的任意数字)
  • B,过程号的前15位(进入过程表的索引)
  • 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

内部,在32位仿真器上,进程号为28位宽. B和C的奇怪定义来自R9B和早期版本的Erlang,其中B是一个15位的进程ID,当达到最大进程ID并重用了较低的ID时,C是一个包装计数器递增.

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.

在erlang分布中,PID稍大一些,因为它们包括节点原子以及其他信息. (分布式PID格式)

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

当内部PID从一个节点发送到另一个节点时,它会自动转换为外部/分布式PID形式,因此,当一个节点上的<0.10.0>(inet_db)可能以<2265.10.0>结尾发送到另一个节点.您可以照常发送给这些PID.

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()]). 

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

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

这篇关于有人可以用Erlang解释Pid(进程标识符)的结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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