[erlang-questions] Why do two processes appear after a spawn?

Dominic Williams xpdoka@REDACTED
Tue Nov 6 22:53:58 CET 2007


Can someone explain to me what is going on here?

Erlang (BEAM) emulator version 5.5.4 [source] [async-threads:0]  
[hipe] [kernel-poll:false]

Eshell V5.5.4  (abort with ^G)
1> F = fun() -> P=processes(), {length(P), lists:member(self(),P)} end.
2> G = fun() -> P=F(), timer:sleep(500), Q=F(), io:fwrite("~p~n", 
[{P,Q}]) end.
3> F().
4> spawn(G).

So the newly spawned process is immediately listed by processes(),  
but a bit later another one appears. What is this 26th process?
Upon further investigation:

6> H = fun(P, Q) -> [process_info(Pid) || Pid <- Q -- P] end.
7> J = fun() -> P=processes(), timer:sleep(500), Q=processes(),  
io:fwrite("~p~n",[H(P,Q)]) end.
8> F().
9> spawn(J).

Any explanation?


Dominic Williams


More information about the erlang-questions mailing list