[erlang-questions] Questions about PID of remote process
B. Nicholson
b.nicholson@REDACTED
Thu May 13 08:26:46 CEST 2010
I thought that the PID of a process was made up of three pieces.
<Node,Lowbits of local processid, high bits of local process_id>.
The low bits and the high bits combine to make up a 28 bit number. So, I
think it is possible to create the same process id by creating 268435456
processes. I wrote a quick program to test this.
-module(proctest).
-export([loop/1]).
loop(N) ->
testspawn(N),
loop(N+1).
testspawn(N) ->
Pid = spawn(fun() -> donothing() end),
PidStr = pid_to_list(Pid),
case PidStr of
"<0.1000.0>" -> io:format("Process ~p found @ ~p (iteration
~p)~n",[Pid,calendar:local_time(),N]);
_ -> ok
end.
donothing() ->
_A = 1 + 2.
The output follows:
Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:8:8] [rq:8]
[async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.7.4 (abort with ^G)
1> c(proctest).
{ok,proctest}
2> proctest:loop().
Process <0.1000.0> found @ {{2010,5,13},{1,14,45}} (iteration 959)
Process <0.1000.0> found @ {{2010,5,13},{1,24,5}} (iteration 268223423)
I think you have to account for 'duplicate' local pids if your Erlang
node is up for a considerable amount of time or goes
through large numbers of processes for some reason.
Hope this helps.
Barry Nicholson
On 05/13/2010 12:17 AM, Bernard Duggan wrote:
> Hi 钱晓明,
>
> On 13/05/10 15:09, 钱晓明 wrote:
>
>> 1. How do I know if the remot process identified by one PID is alive? I
>> know I can send a message to it, and receive response with timeout. But I
>> hope there is some way more conveniently.
>>
>>
> One option (the one we use) is erlang:monitor(process, Pid). If he Pid
> dies or the node goes down, or is down when you make the monitor() call
> you'll get a message notifying you of the fact.
>
>> 2. Can the PID be reused in one node? If a process identified by one PID
>> died, then this PID can be used to identify other process created later?
>>
>>
> Not as far as I know - the fact that you can call node(Pid) to get the
> node on which a PID resides, even after that PID has terminated, implies
> that the PID embeds (or at least links to) unique node information.
>
> Cheers,
>
> Bernard
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>
>
More information about the erlang-questions
mailing list