Elixir Links vs. Monitors

  • A monitored process (Process.monitor(pid)) sends up a :DOWN message when the child process is done.

    • :reason is set to :normal if the process exited cleanly
    • :reason is set to the error instance otherwise.
  • A linked process (start_link) sends up an :EXIT message when the child process is done.

    • By default, Elixir handles this message internally:
      • The message is swallowed if :reason is :normal
      • The error is re-thrown on the parent if :reason is an error instance (and both parent and child are terminated)
    • If the parent calls Process.flag(:trap_exit, true) to indicate that it wants to trap exits, the :EXIT message is received like any other message, and the parent is not automatically terminated even if the :EXIT represents an error.