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

Khitai Pang <>
Tue Dec 6 11:35:23 CET 2016

Hi Adrian,

Thank you for the information but unfortunately it's not the cause of my problem.  If I add 'user' io:format():

()6> run_on_all_nodes().

()7> [spawn(Node, fun() -> io:format(user, "This runs on ~p~n", [node()]) end) || Node <- nodes()].

()8> [spawn(Node, fun() -> io:format("This runs on ~p~n", [node()]) end) || Node <- nodes()].
This runs on 
This runs on 
This runs on 

It doesn't seem to be I/O channeling problem, it seems that the spawned processes just don't run...


On 2016/12/6 17:52, Adrian Roe wrote:
This confused me for a while as well…

To quote 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()])
io:format(user, "This runs on ~p~n", [node()])

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


On 6 Dec 2016, at 09:34, Khitai Pang <<mailto:><mailto:>> wrote:


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().

If I manually run the spawn command in the attached shell, it all works

()3> [spawn(Node, fun() -> io:format("This runs on ~p~n",
[node()]) end) || Node <- nodes()].
This runs on 
This runs on 
This runs on 

Any idea?

erlang-questions mailing list

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

More information about the erlang-questions mailing list