A behaviour module for implementing a supervisor, a process which
supervises other processes called child processes. A child
process can either be another supervisor or a worker process.
Worker processes are normally implemented using one of
the
A supervisor assumes the definition of which child processes to supervise to be located in a callback module exporting a pre-defined set of functions.
Unless otherwise stated, all functions in this module will fail if the specified supervisor does not exist or if bad arguments are given.
The supervisor is responsible for starting, stopping and monitoring its child processes. The basic idea of a supervisor is that it should keep its child processes alive by restarting them when necessary.
The children of a supervisor is defined as a list of child specifications. When the supervisor is started, the child processes are started in order from left to right according to this list. When the supervisor terminates, it first terminates its child processes in reversed start order, from right to left.
A supervisor can have one of the following restart strategies:
The functions
To prevent a supervisor from getting into an infinite loop of
child process terminations and restarts, a maximum restart frequency is defined using two integer values
This is the type definition of a child specification:
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()
The start function must create and link to the child
process, and should return
The start function can also return
If something goes wrong, the function may also return an
error tuple
Note that the
If the child process is another supervisor,
Important note on simple-one-for-one supervisors: The dynamically created child processes of a simple-one-for-one supervisor are not explicitly killed, regardless of shutdown strategy, but are expected to terminate when the supervisor does (that is, when an exit signal from the parent process is received).
Note that all child processes implemented using the standard OTP behavior modules automatically adhere to the shutdown protocol.
Internally, the supervisor also keeps track of the pid
Creates a supervisor process as part of a supervision tree. The function will, among other things, ensure that the supervisor is linked to the calling process (its supervisor).
The created supervisor process calls
If
If the supervisor and its child processes are successfully
created (i.e. if all child process start functions return
If
If any child process start function fails or returns an error
tuple or an erroneous value, the function returns
Dynamically adds a child specification to the supervisor
If the case of a
If there already exists a child specification with
the specified
If the child process start function returns
If the child process start function returns
If the child process start function returns an error tuple or
an erroneous value, or if it fails, the child specification is
discarded and the function returns
Tells the supervisor
See
If successful, the function returns
Tells the supervisor
See
If successful, the function returns
Tells the supervisor
See
If the child specification identified by
If the child process start function returns
If the child process start function returns
If the child process start function returns an error tuple or
an erroneous value, or if it fails, the function returns
Returns a newly created list with information about all child
specifications and child processes belonging to
the supervisor
Note that calling this function when supervising a large number of children under low memory conditions can cause an out of memory exception.
See
The information given for each child specification/process is:
Returns a property list (see
This function takes a list of child specification as argument
and returns
The following functions should be exported from a
Whenever a supervisor is started using
Note that when the restart strategy is
The function may also return