"raw" or "verbatim" PIDs?

Joe Armstrong (AL/EAB) joe.armstrong@REDACTED
Tue Jul 11 11:20:34 CEST 2006


The problem with pid_to_pid/3 and pid/3 is that
they are not guaranteed to work forever.

Suppose you find out that the pid of your program is
<0.97.0> and that you say Pid = pid(0,97,0),
if the program has not died between the point in time
when you found out that is was <0.97.0> and the time when
you evaluate pid(0,97,0) then Pid will get the correct value.

If the process is dead or non-existent, you'll still get
a valid Pid

So if I do

	pid(0,123,22) ! abc

This will work - it just sends a message to a non-existing process.

Now if the pid created by evaluating pid(X,Y,Z) responds to your
messages
there is no guarantee that this is the process you thought it was.

This can happen if

	- there is a very long time between finding the value of
	  the three integers representing the pid and creating a new Pid
	- the original process died between the two operations above
	- the Pid got "recycled" (ie is reused, for a new process,
	  this can happen after a long time)
        
This is very unlikely but can happen.

As the manual says - "It should not be used in
application programs"


/Joe

> -----Original Message-----
> From: owner-erlang-questions@REDACTED 
> [mailto:owner-erlang-questions@REDACTED] On Behalf Of 
> Thomas Lindgren
> Sent: den 11 juli 2006 09:38
> To: erlang-questions@REDACTED
> Subject: Re: "raw" or "verbatim" PIDs?
> 
> 
> 
> --- Jon Slenk <jonslenk@REDACTED> wrote:
> 
> > Ah, I finally figured out that I can use list_to_pid(), 
> although there 
> > are dire warnings in the documentation that it and
> > pid_to_list() should not be
> > used in application code. (Is there a "constructor"
> > for PIDs, or does one
> > have to use list_to_pid()?)
> 
> PIDs are normally considered opaque handles (if you
> will) to processes, and ordinary usage is to construct PIDs 
> with spawn/spawn_link/self, then pass them around.  
> 
> As far as I know, the list_to_pid/1 and pid/3 functions are 
> basically intended for debugging. There are more such 
> convenience functions (e.g.,
> processes/0) but using them in applications can lead to a 
> system which is quite difficult to understand -- hence the warnings.
> 
> Best,
> Thomas
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection 
> around http://mail.yahoo.com 
> 



More information about the erlang-questions mailing list