antonpuz
antonpuz

Reputation: 3316

Processes spawned on connected nodes get same PID

I have four Erlang nodes working together on multi-process application. In my order one process is monitoring which draws the location of the processes on the area and the three other nodes handle the processes location and movement. On the monitor I use an ETS database to store the locations when the key is the process PID. I have noticed that the nodes creates processes which have the same PIDs which obviously interrupts with the management of the entire system.

I have tried to connect the processes with:

net_adm:ping(...).
net_kernel:connect(...).

I was hoping that when the nodes will be aware of each other they will give different PIDs but that did not work.

Upvotes: 3

Views: 327

Answers (1)

legoscia
legoscia

Reputation: 41568

The PIDs may be printed the same, e.g. <0.42.0>, but that's just an output convention: PIDs on the local node are printed with the first number being 0. If you'd send this PID to another node and print it there, it would be printed as <2265.42.0> or similar. PIDs are always associated with the name of the node where the process is running, and you can extract it with node(Pid). Therefore, PIDs from different nodes will never compare equal.

This answer goes into more details about the structure of a PID.

Upvotes: 7

Related Questions