简体   繁体   English

全局注册进程未注册

[英]Globally registered process is not registered

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.当我运行代码时,它不会抛出任何错误,但是当我尝试 whereis(process) 时,我在产生它的节点上未定义。

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:当我尝试从任何节点(主节点或我在其上创建进程的节点) whereis(process) 时,它说:

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

To register on several nodes you have to:要在多个节点上注册,您必须:

  • start several nodes启动几个节点
  • ensure they use the same cookie确保他们使用相同的 cookie
  • connect them (for example in node A, execute net_adm:ping(B) )连接它们(例如在节点 A 中,执行net_adm:ping(B)
  • start a process on node B with spawn(node,...)使用spawn(node,...)在节点 B 上启动一个进程
  • register it with global:register_name(name, Pid)使用global:register_name(name, Pid)
  • check the registration with global:whereis_name(name)检查注册global:whereis_name(name)

you miss at least the last point, but all of them are necessary.你至少错过了最后一点,但所有这些都是必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM