[erlang-questions] Why do two processes appear after a spawn?
Dominic Williams
xpdoka@REDACTED
Tue Nov 6 22:53:58 CET 2007
Hello,
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.
#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> spawn(G).
<0.35.0>
{{25,true},{26,true}}
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.
#Fun<erl_eval.12.24269688>
7> J = fun() -> P=processes(), timer:sleep(500), Q=processes(),
io:fwrite("~p~n",[H(P,Q)]) end.
#Fun<erl_eval.20.112921583>
8> F().
{24,true}
9> spawn(J).
<0.42.0>
[[{current_function,{io,wait_io_mon_reply,2}},
{initial_call,{erlang,apply,2}},
{status,waiting},
{message_queue_len,0},
{messages,[]},
{links,[<0.25.0>]},
{dictionary,[]},
{trap_exit,false},
{error_handler,error_handler},
{priority,normal},
{group_leader,<0.24.0>},
{heap_size,233},
{stack_size,6},
{reductions,15},
{garbage_collection,[{fullsweep_after,65535}]}]]
Any explanation?
Thanks,
Dominic Williams
http://dominicwilliams.net
----
More information about the erlang-questions
mailing list