Storing pids

Per Hedeland hedeland@REDACTED
Thu Jan 5 15:41:50 CET 2006


Joel Reymont <joelr1@REDACTED> wrote:
>
>md5 would probably be too slow.
>
>The simplest solution that I found was to just store the pid.
>
>The issue is that once I try to create a pid using list_to_pid it  
>won't let me if the original node is down or otherwise. I'll try  
>storing a tuple of 3 numbers (using Matt's approach) since  I don't  
>normally need to inspect the processes. If I do and the node is still  
>up I'll surely have no problems with list_to_pid and the 3 numbers  
>that I stored.

Read again what Mats wrote some messages back: "numbering is different
on each erlang node". This means that

a) The numbers [4000, 34, 0] may represent one process on one node, and
   a totally different process on another - not very likely, but
   possible. More likely is that they don't represent any process at all
   on another node, i.e.

b) Trying to interpret the numbers as a process on a different node than
   the one where they were obtained, or even interpreting the first
   number as a particular node, is unreliable or more likely impossible.

Mats' suggestion of replacing the node number with the node name is
definitely the way to go. Which just happens to be how pids are
represented "on the wire", which just happens to mean that doing
term_to_binary/1 on a pid will result in something that fits your bill
perfectly. It can even be binary_to_term'ed back to the correct
representation of the original pid on a different node. (It can, but I
wouldn't bet my life on it...:-)

--Per Hedeland



More information about the erlang-questions mailing list