2

I'm using

spawn (node, module, function, Args) 
global:register_name(name, pid)

To register a process on a different node globally.

Here's the code

Pid = spawn(mi, loop, [X]),
io:format("Glavni PID: ~w~n", [Pid]),
register(glavni, Pid),

Pid1 = spawn (prvi@Molly, mi, loop_prvi, []),
io:format("Prvi PID: ~w~n", [Pid1]),
global:register_name (prvi, Pid1),

When I run the code, it doesn't throw any error but when I try whereis(process) I get undefined on a node that spawned it.

Here's what process' console says:

Pid = spawn(mi, loop, [X]),
io:format("Glavni PID: ~w~n", [Pid]),
register(glavni, Pid),

Pid1 = spawn (prvi@Molly, mi, loop_prvi, []),
io:format("Prvi PID: ~w~n", [Pid1]),
global:register_name (prvi, Pid1),

And when I try to whereis(process) from any node, either the master node or the node I created the process on, it says:

(prvi@Molly)2> whereis(prvi).
undefined
(prvi@Molly)3> whereis(prvi@Molly).
undefined

1 Answer 1

3

To register on several nodes you have to:

  • start several nodes
  • ensure they use the same cookie
  • connect them (for example in node A, execute net_adm:ping(B))
  • start a process on node B with spawn(node,...)
  • register it with global:register_name(name, Pid)
  • check the registration with global:whereis_name(name)

you miss at least the last point, but all of them are necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.