Globally registered process is not registered

强颜欢笑 提交于 2019-12-11 03:14:40

问题


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:


To register on several nodes you have to:

  • start sevral 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.



来源:https://stackoverflow.com/questions/23385935/globally-registered-process-is-not-registered

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!