Starting Processes with Links

Let's learn how our supervisors use notifications to handle failures.

Notifications

Supervisors are built on notification, an interesting primitive. Remember, when a process uses start_link/2 to create a child process, the Erlang BEAM will notify the parent process when the child process ends. This capability can work in a couple of ways.

spawn_link

First, using spawn_link causes all linked processes to end with the same error if any one of them ends. That may sound like a weird behavior to want, but if the top-level processes of our system end, we don’t want their child processes carrying on without them.

Here’s how spawn_link works. Let’s spawn a process that crashes, like this:

Executable

Get hands-on with 1200+ tech skills courses.