erlang (process) API Reference
The erlang module's core concurrency primitives — spawn, message sending, linking, and monitoring for building fault-tolerant systems.
process functions
Functions for creating, observing, and controlling BEAM processes. Processes share no memory and communicate only by asynchronous message passing.
spawn(Module, Function, Args) -> pid()Create a new BEAM process that calls Module:Function(Args). Returns immediately with the new process's PID.
Returns: pid() — the identifier of the newly created process.
Pid ! Message -> MessageSend Message asynchronously to the mailbox of the process identified by Pid. Delivery is guaranteed and order is preserved per sender-recipient pair.
Returns: Returns Message itself, enabling broadcasts: [P ! Msg || P <- Pids].
receive Patterns after Timeout -> Body endScan the mailbox in arrival order for the first message matching a Pattern (with optional guard). If none match, block until one arrives or Timeout (ms) elapses.
Returns: The value of the matched clause's Body (or the after clause's Body on timeout).
link(Pid) -> trueCreate a bidirectional link between the current process and Pid. If either process exits, the other receives an exit signal — by default crashing it too.
Returns: true. Idempotent: linking an already-linked process is a no-op.
monitor(process, Pid) -> reference()Create a one-way monitor: the calling process observes Pid, but Pid is unaffected. When Pid dies, the caller receives {'DOWN', Ref, process, Pid, Reason}.
Returns: reference() — unique tag used to identify this monitor and match its 'DOWN' message.
exit(Reason) -> no_return() / exit(Pid, Reason) -> trueWith one argument, terminate the current process with Reason. With two arguments, send an exit signal to Pid (the current process keeps running).
Returns: exit/1 never returns. exit/2 returns true.
make_ref() -> reference()Create a unique reference, guaranteed never to be returned again by any call to make_ref on any node in the cluster.
Returns: reference() — unique token used to tag requests, monitors, and replies.
process_flag(Flag, Value) -> OldValueSet a per-process flag for the current process only. The most important is trap_exit, which converts incoming exit signals into messages.
Returns: The previous value of the flag.