A local process name associates a BEAM process with an atom resolvable only within the current BEAM instance. It lets other processes communicate without retaining or passing the server’s PID. section 5.3.5
Registering a process imposes a small set of operational constraints:
- Register it with Process.register(pid, name), where name must be an atom. section 5.3.5
- Allow only one registered name per process and one process per name; violations raise an error. section 5.3.5
- Use the name for process discovery when supervised restarts make an old PID invalid. section 8.3.2
GenServer.start accepts a name option, allowing GenServer.call and GenServer.cast to target the registered name directly. Using the module name, or __MODULE__, removes PID plumbing from the public interface while preserving a singleton process within the BEAM instance. section 6.2.5
Named server access
A to-do server registered as :todo_server can expose add_entry and entries functions without requiring callers to store or pass its PID. The functions send requests to :todo_server internally, simplifying repeated use of the server. section 5.3.5
iex(1)> Process.register(self(), :some_name) #1
iex(2)> send(:some_name, :msg) #2
iex(3)> receive do #3
msg -> IO.puts("received #{msg}")
end
received msg
Try registering the current shell process, send a message through its local name, and receive it. section 5.3.5
The scope remains local in a multinode system: different nodes may each register the same atom, and remote access uses {name, node}. Local registration therefore names a process on one node rather than globally across the cluster. section 12.1.2
