Process.monitor

You're seeing just the function monitor, go back to Process module for more information.

Specs

monitor(pid() | {name, node()} | name) :: reference() when name: atom()

Starts monitoring the given item from the calling process.

Once the monitored process dies, a message is delivered to the monitoring process in the shape of:

{:DOWN, ref, :process, object, reason}

where:

  • ref is a monitor reference returned by this function;
  • object is either a pid of the monitored process (if monitoring a PID) or {name, node} (if monitoring a remote or local name);
  • reason is the exit reason.

If the process is already dead when calling Process.monitor/1, a :DOWN message is delivered immediately.

See "The need for monitoring" for an example. See :erlang.monitor/2 for more information.

Inlined by the compiler.

Examples

pid = spawn(fn -> 1 + 2 end)
#=> #PID<0.118.0>
Process.monitor(pid)
#=> #Reference<0.906660723.3006791681.40191>
Process.exit(pid, :kill)
#=> true
receive do
  msg -> msg
end
#=> {:DOWN, #Reference<0.906660723.3006791681.40191>, :process, #PID<0.118.0>, :noproc}