SV: Killing Supervisor
Samuel Rivas
samuel@REDACTED
Fri Apr 28 08:56:18 CEST 2006
Surindar Sivanesan wrote:
> Hi,
> I thank Serge, Lennart and Samuel for the reply to my doubt.
> But still I haven't get the clear idea of stopping the entire supervision
> tree. Kindly do my favour.
>
> On 4/26/06, Samuel Rivas wrote:
>
> Lennart Öhman wrote:
> > If you simply do exit(Pid,kill) on the supervisor, it will not
> > be given the chance of terminating its children in an ordered
> > way.
>
> Calling exit(SupervisorPid, shutdown) in the supervisor's parent
> process would do the trick.
Take a look to Erlang Design Principles, specially to:
http://erlang.se/doc/doc-5.4.13/doc/design_principles/sup_princ.html#5.10
OTP behaviours define a standard shutdown process. The clean way to
shutdown a supervisor is, as Lennart said, to make it child of another
supervisor and use supervisor API to stop it. Obviously, you need a top
supervisor. You can shutdown the top supervisor if you start it as part
of an OTP application.
What happens with the two workarounds proposed is:
- exit(Pid, kill) sends Pid an exit signal that cannot be trapped, so
the supervisor dies instantaneously and the exit signal propagates
to its children since they are linked. Children die in an unspecified
order.
- exit(Pid, shutdown) makes what a parent supervisor would do to
terminate the supervisor. That way, the supervisor receives the
signal, stops its children cleanly and terminates itself.
Regards
--
Samuel
More information about the erlang-questions
mailing list