Mostly Harmless has asked for the wisdom of the Perl Monks concerning the following question:
f1() f2() in background. f3() in background. f4() wait for 'f2' f5() wait for 'f3'
All tasks performed in each step is critical, and if any of them fail, then the parent process must kill all children and shut itself down. For instance, if 'f3' encountered an error, like a SEGV or someone accidentally sending it a SIGKILL, then parent should know about it and exit immediately.
I tried various alternatives:
1. Install an ALRM handler in the parent. This handler would
periodically check if the child has exited, and if so,
it would die. But if any module installs an ALRM handler
the whole scheme would fail. I tried using
Alarm::Concurrent, but found it to be buggy. Also, the
existing code has sleep() in couple of places, which may
interfere with the ALRM handler.
2. Tie %SIG and capture CHLD, and override with a
custom subroutine. But this scheme also needs wait()
and waitpid() are overridden. This may be doable, but
looks too complicated, and may affect several parts
of the existing code that spawns forground processes.
3. At various parts of the parent code, call a function
that would check if the child has exited. This won't
work when the parent is in a blocking call.
4. Make the parent do no work, other than simple child
monitoring. This needs lots of code changes for my
existing application, and is not feasible.
Alas, UNIX signals suck ! :-( Anyone has been stuck with this problem before ? Any suggestions ?
thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to asynchronisly get notified of a child exit
by Fletch (Bishop) on Jul 07, 2005 at 18:16 UTC | |
by Mostly Harmless (Initiate) on Jul 07, 2005 at 18:23 UTC | |
by Fletch (Bishop) on Jul 07, 2005 at 18:49 UTC | |
by Mostly Harmless (Initiate) on Jul 08, 2005 at 05:44 UTC | |
|
Re: How to asynchronisly get notified of a child exit
by Transient (Hermit) on Jul 07, 2005 at 17:58 UTC | |
by Mostly Harmless (Initiate) on Jul 07, 2005 at 18:17 UTC | |
|
Re: How to asynchronisly get notified of a child exit
by salva (Canon) on Jul 08, 2005 at 10:41 UTC |