[erlang-questions] Pid after node restart

Pavel Baturko pabftk@REDACTED
Mon Sep 29 11:14:14 CEST 2014


Hi,

I have a question about internal structure of pid and possibility to
compare pids in distributed system.
I see strange (for me) behavior of erlang (version 17.1) and I need help to
explain this.
My case is:
I have 2 connected nodes.

   1. On node 1 I generate a pid P (<0.X.0>)
   2. P is transfered to node 2 (on node 2 I receive it as <Y.X.0>)
   3. P is transfered back from node 2 to node 1 (I'm receiving it as P2)
   4. P2 is recognized as local pid (<0.X.0>)
   5. I can compare P and P2 on node 1 and they are identical
   6. I'm restarting node 1
   7. On node 1 I generate the same pid P as in step 1 (<0.X.0>)
   8. I repeat step 3, again receive initial pid as P2
   9. P2 is recognized as local pid (<0.X.0>) - as before
   10. But now P == P2 returns false.
   11. Also P == list_to_pid(pid_to_list(P2)) returns true

Could someone explain this behavior?
What is changing in internal pid representation after node restart so
comparison in step 10 returns false? And why comparison in step 11 returns
true?

My code (first lines for node 1, after empty line code for node 2):
------------
erl -sname n1 -setcookie t

erl -sname n2 -setcookie t
------------
net_kernel:connect_node('n2@REDACTED').
global:register_name(n1, self()).

global:register_name(n2, self()).
------------
P = pid(0,1,0).
global:send(n2, P).

receive P -> P end.
------------
receive P2 -> P2 end.
P == P2. % this will return true

global:send(n1, P).
------------
%restart n1
net_kernel:connect_node('n2@REDACTED').
global:register_name(n1, self()).
P = pid(0,1,0).
receive P2 -> P2 end.
P == P2. % this will return false

global:send(n1, P).
------------

Thanks,
Pavel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140929/706c0b31/attachment.htm>


More information about the erlang-questions mailing list