[erlang-questions] Newbie question - how do I get global:register_name() to work?

G Bulmer <>
Tue Sep 18 23:51:23 CEST 2007

I apologise for this newbie question, but ...
Would someone please explain how to get global:register_name()/ 
global:whereis_name() to work across nodes?

I have some very simple, experimental, local-registry based code  
which looks roughly like this:
register(lookup, spawn(fun() -> some_fun() end)),

and uses this message sending syntax from the 'remote' machine:
{ lookup, '' } ! { some_message }

This code works okay across nodes on the same machine, and nodes on  
two machines; so cookie, -name server, etc. seem to be fine.

I've tried converting it to use global:register_name(...), etc:
Status = global:register_name(lookup, Pid = spawn(fun() -> some_fun()  

This returns 'yes' as the value of Status, and seems to work within  
the VM that calls global:register_name(), i.e. global:whereis_name 
(lookup) returns the same pid value as bound to Pid in register_name,  
and global:registered_names() returns [lookup].

BUT in a second VM, on the same machine it fails (the 2nd VM is  
started with erl -name client). Specifically:
global:whereis_name(lookup)   returns 'undefined', and
global: registered_names()   returns [].

I can see the process global_name_server mentioned in the global:  
module doc, in response to i() to the shell:
<0.11.0>              global:init/1                           
233       69    0
global_name_server    gen_server:loop/6                       12

What am I missing?
Help and advice would be much appreciated.


More information about the erlang-questions mailing list