Understanding Elixir Supervisor

This and the other “Deck” posts are a repurposing of flashcard study decks to Q&A blog posts.

What is the function of an Elixir Supervisor?

It is a process that monitors other processes and restarts them based on a specified supervision strategy.

How are supervisors related to the Elixir axiom "let it crash"?

Supervisors will spin up new processes in the event of a failure. If a process errors/fails a new one will be started without the developer having to step in and restart anything. Aka they can "let it crash".

How are processes under supervision related to the Supervising process?

They are considered child processes of the supervisor.

How do you start a supervisor that monitors child processes?

You pass a list of child processes to the supervisor. Each child process is a `Map` that contains keys of `id` and `start`. The `id` is the process and `start` is a `Tuple` containing information on how to run the process. Example below:
children = [ %{ id: ChildProcess, start: {ChildProcess, :start_link, [[:initial_state]]} } ] 
{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)

What supervision strategy should be used if you want only the specific child process that terminates to be restarted?


What supervision strategy should be used if you want all child processes to be restarted if any of them terminate?


What supervision strategy should be used if you want all processes started after the terminated one to also be terminated and restarted?


What is a supervision tree?

It is a hierarchy of process supervisors. This means that a process that is under supervision can also have its own child processes that it supervises.