[erlang-questions] processes spawned on remote nodes don't run

Adrian Roe <>
Tue Dec 6 10:52:42 CET 2016


This confused me for a while as well…

To quote http://erlang.org/doc/man/erlang.html <http://erlang.org/doc/man/erlang.html>

group_leader() -> pid()


Returns the process identifier of the group leader for the process evaluating the function.

Every process is a member of some process group and all groups have a group leader. All I/O from the group is channeled to the group leader. When a new process is spawned, it gets the same group leader as the spawning process. Initially, at system startup, init is both its own group leader and the group leader of all processes.

There’s a helpful post here http://erlang.org/pipermail/erlang-questions/2008-April/034573.html <http://erlang.org/pipermail/erlang-questions/2008-April/034573.html> that talks about exactly what you are seeing.

If you change the 
	io:format("This runs on ~p~n", [node()]) 
to 
	io:format(user, "This runs on ~p~n", [node()])

I strongly suspect you will see the output you were expecting…

Adrian

> On 6 Dec 2016, at 09:34, Khitai Pang <> wrote:
> 
> Hi,
> 
> I have the following function in user_default.erl:
> 
> run_on_all_nodes() ->
>     [spawn(Node, fun() ->
>                          io:format("This runs on ~p~n", [node()])
>                  end) || Node <- nodes()].
> 
> When I run this function, processes can be spawned on remote nodes but 
> it seems that they don't run:
> 
> ()1> nodes().
> []
> 
> ()2> run_on_all_nodes().
> [<27616.12336.0>,<27612.15341.39>,<27615.22399.50>]
> 
> If I manually run the spawn command in the attached shell, it all works 
> fine:
> 
> ()3> [spawn(Node, fun() -> io:format("This runs on ~p~n", 
> [node()]) end) || Node <- nodes()].
> This runs on 
> This runs on 
> This runs on 
> [<27616.12339.0>,<27612.15569.39>,<27615.22640.50>]
> 
> 
> Any idea?
> 
> 
> Thanks
> Khitai
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161206/777a4302/attachment.html>


More information about the erlang-questions mailing list