What is a Supervisor REALLY doing?

Chandru <>
Tue Aug 29 20:11:27 CEST 2006


Hi Jeff,

On 29/08/06, Jeff Crane <> wrote:
>
> I have no book and have taken no class. I'm in
> southern california and have been fiddling with erlang
> for a month. I understand the PURPOSE of a supervisor.
> To monitor child(?) process states.


It is not just to monitor. It is it monitor and restart processes as
specified.

This is the only implementation of Supervisor
> behaviour I can find (it's near the bottom).
>
> http://www.matt-mcdonnell.com/code/code_erl/erl_course/erl_course.html
>
> Is this ms.erl an accurate representation of a
> Supervisor implementation?


Have you seen supervisor.erl in the stdlib application which comes with
Erlang/OTP?

I can't find any documentation for an erlang
> supervisor. The examples I can find on the web:


http://www.erlang.org/doc/doc-5.5/lib/stdlib-1.14/doc/html/supervisor.html

>From an erlang beginner's perspective this is a
> completely uncomprehensible mechanism. For example:
>
> http://www.erlang.org/doc/doc-5.4.12/doc/design_principles/sup_princ.html
>
> -module(ch_sup).
> -behaviour(supervisor). %% Why can't a I find the
> actual implementation of this behaviour, defined line
> by line so I understand what's going on?
>
> -export([start_link/0]).
> -export([init/1]).
>
> start_link() -> %% Where, when, why would I call this?


This is called by the  supervisor module.  Basically, if you want a process
to be supervised, you write a child specification. From the documentation,
it looks like this:

child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules}
 Id = term()
 StartFunc = {M,F,A}
  M = F = atom()
  A = [term()]
 Restart = permanent | transient | temporary
 Shutdown = brutal_kill | int()>=0 | infinity
 Type = worker | supervisor
 Modules = [Module] | dynamic
  Module = atom()



I can't understand how to add a supervisor without a
> solid understanding of how they work. This is one of
> many problems I have had trying to learn erlang.


Have a read through the documentation and I'm sure it'll answer a lot of
your questions. All OTP behaviours are part of the stdlib application.

cheers
Chandru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060829/1a00ff4d/attachment.html>


More information about the erlang-questions mailing list