[erlang-questions] stop supervisor when no children are running

Essien Essien essiene@REDACTED
Tue May 5 14:23:20 CEST 2009


On Tue, May 5, 2009 at 8:50 AM, David Sveningsson <ext@REDACTED> wrote:
> Hash: SHA1
> Richard Andrews wrote:
>> You could tell the supervisor's parent to stop it. Then let the gen_server worker get killed off as its supervisor shuts down.
> Yes, but how? The parent is the process who start the supervisor right?
> I can't find a function to stop it anyhow.

Usually, you would package everything as an application, then call
application:start() and application:stop(), to start and stop your top
level supervisor.

> Also, I would like the supervisor to stop when all the children have
> stopped, not stop the supervisor to stop its children.

You could actually have another child of that supervisor, a gen_server
who's task it is to monitor the other children, and when they all go
down, it then commits sepuku, or something of that nature :)

> What I am doing is starting a supervisor with some children which may
> run for some time but will finish eventually. When all the children have
> stopped I want the entire os process to stop, returning 0.

If you used my suicidal gen_server suggestion, then when it determines
that all your other children are dead, via some flags which you can
set, then this monitor process can call application:stop() die normal
and call application:stop(your_app_name) in terminate/2

> I did this without using OTP earlier but started converting to
> supervisor and gen_servers since I had multiple issues with error
> handling and debugging. OTP solved those issues and generally made the
> code better (as in maintainable and easier to read).

Yeah.... OTP is very helpfull like that. Makes things cleaner and has
the... "Damn! Ofcourse!" factor :)

hope that helps in someway.

> Version: GnuPG v2.0.11 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> iEYEARECAAYFAkn/778ACgkQ6pa1H/H5pqXNRwCePM2eC9ViSMBOo5EllA13Bxr6
> grUAoNEnYCzcxB3rIL3GNOncfkuoAtgH
> =Pw6q
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list