It is possible to register a process (pid) to a global alias.
This can be achieved with the build in register(Alias, Pid)
function, where Alias
is the atom to access the process as and Pid
is the process id.
The alias will be globally available!
It is very easy to create shared state, wich is usually not preferable. (See also here)
It is possible to unregister a process with unregister(Pid)
and receive the pid from an alias with whereis(Alias)
.
Use registered()
for a list of all registered aliases.
The example registers the Atom foo to the pid of the current process and sends a message using the registered Atom.
1> register(foo, self()).
true
2> foo ! 'hello world'.
'hello world'