Local register of a group leader

1.1k Views Asked by At

I try to register group_leader() locally using

register( iogl, group_leader()).

but it returns with bad_arg error

** exception error: bad argument
 in function  register/2
    called as register(iogl,<0.29.0>)

How can i give a local symbolic name to the group_leader() process?

I do able to register it as a global name using

global:register_name(iogl, group_leader()).

but its not what I need.

UPD: The real problem:

I create process on remote node (RN) using spawn from local node(LN), but i want that process to use group_leader of RN , not LN for io operations. Thank you.

3

There are 3 best solutions below

3
On

The easiest way to do this is for the code you spawn on the remote node to do:

io:format(user, FormatString, FormatArguments)

This will cause the remote code to use the remote IO group leader for output. You could also have the code you spawn remotely to set its group_leader to the pid of user shortly after it is spawned, it could then use io:format/2 normally and it will send its output to the correct place on the remote node.

I guess the short answer is that the registered(symbolic) name for the standard group leader process on any node is user.

0
On

To spawn at remote node would help. You need some spawner process at each node, just like standard rpc module does.

Couudant's rexi library implements such functions. https://github.com/cloudant/rexi See rexi:cast/3:

rexi:cast(remote_node, self(), {io, format, ["~p~n", ["where to go the output?"]]}).
2
On

Of course you can register it, the group_leader is a pid like any pid. There are two reasons that you get the error:

  • That name is already registered.
  • The process is already dead, there is no checking that the group_leader process is alive.

And I repeat @OJ's question of why you would want to give it a name.