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

Nicolas Charpentier <>
Wed Nov 7 00:20:13 CET 2007


Hi,
I used dbg module to produce some traces which can be useful to 'erlang
gurus' for the explanation.

1> F = fun() -> P=processes(), {length(P), lists:member(self(),P)} end.
#Fun<erl_eval.20.112921583>
2> G = fun() -> P=F(), timer:sleep(500), Q=F(), io:fwrite("~p~n",
[{P,Q}]) end.
#Fun<erl_eval.20.112921583>
3> F().
{24,true}
4>dbg:tracer().
5>dbg:p(all,[p]).
6>spawn(G).
(<0.38.0>) exit {ok,[{call,2,{atom,2,spawn},[{var,2,'G'}]}],3}
(<0.25.0>) getting_unlinked <0.38.0>
(<0.30.0>) spawn <0.39.0> as erlang:apply(#Fun<erl_eval.20.62269157>,[])
(<0.25.0>) spawn <0.40.0> as erlang:apply(#Fun<shell.3.58263380>,[])
 (<0.25.0>) link <0.40.0>
(<0.2.0>) getting_unlinked #Port<0.99>
(<0.39.0>) exit normal

I removed those lines from the output as they are function results:
<0.39.0>
{{27,true},{28,true}}



Regards.

----
Nicolas Charpentier
http://charpi.net



More information about the erlang-questions mailing list