liveBook · Manning

Local process name

As explained in Elixir in Action, Third Edition

Local process registration is the act of associating a process with an atom name that is resolvable only within the current BEAM instance.

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

How Elixir in Action, Third Edition covers it

How deep it goes
Explains registration constraints, GenServer integration, restart behavior, and node-local scope, but does not develop a global naming system.
Examples
Demonstrates shell messaging, named GenServers, to-do servers, and identical names registered on separate nodes.
What it assumes
Assumes familiarity with BEAM processes and PIDs while teaching how names replace PID passing for reachable server processes.
What you can do after
Apply Process.register, named GenServer calls, and local-name discovery across supervised process restarts.
How it connects
Connects process identifiers, process discovery, GenServer, supervision, fault tolerance, and distributed systems.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.