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

David Sveningsson <>
Tue May 5 09:50:23 CEST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Richard Andrews wrote:
>> Hi, I'm using a supervisor to restart a gen_server if it crashes (using
>> transient restart rule). I would like to have the supervisor stop if the
>> the gen_server process is stopped normally. Even better would be if the
>> erlang process could be terminated (init:stop or similar).
>>
>> Is there a way to do this?
> 
> 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.

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

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.

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).

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkn/778ACgkQ6pa1H/H5pqXNRwCePM2eC9ViSMBOo5EllA13Bxr6
grUAoNEnYCzcxB3rIL3GNOncfkuoAtgH
=Pw6q
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list