[erlang-questions] stop supervisor when no children are running
Tue May 5 14:23:20 CEST 2009
On Tue, May 5, 2009 at 8:50 AM, David Sveningsson <> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> 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
> 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.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.11 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> -----END PGP SIGNATURE-----
> erlang-questions mailing list
More information about the erlang-questions