|Welcome to the Monastery|
Complex and reliable signal handling.by vsespb (Hermit)
|on May 31, 2013 at 15:57 UTC||Need Help??|
vsespb has asked for the
wisdom of the Perl Monks concerning the following question:
I have fork()'ing application with one parent process and multiple children processes. It works fine, but I am having problems implementing graceful termination after SIGINT/SIGHUP/SIGTERM.
1. I use File::Temp for temporary files (I need named temporary files). Children processes should handle SIGINT/SIGHUP, because otherwise destructors are not called and temporary files left on disk.
2. If child dies with exception, parent should handle SIGCHLD, terminate all other children and terminate itself.
3. If parent dies (either because of exception, or maybe because of SIGTERM) it should terminate all children.
After I added signals handling to children code, I am getting errors (often or rare)
or if I try to modify this code, it works a bit better, but I still see errors sometimes. Also sometimes Segfault happening.
My perl version is 5.10 on linux, I understand that it's hard to test particular signal handling code on all perl versions, but I am looking for a scheme, that is reliable by design and unlikely produce bug.
Or maybe you can find bug in my above code?
p.s. I've read about sigaction() but still don't see how it can help and why