jpfarmer has asked for the wisdom of the Perl Monks concerning the following question:

Greetings fellow monks!

I have an application that forks off a continually-running child process. In the course of the child's life, it frequently shells out to run different applications. As a result, it will sometimes disregard signals (INT and HUP) if the signal is sent while the child is in one of these processes.

Is there a way to correct this behavior? I would like it to wait for the forked application to complete then perform whatever the signal requires. Can I only do this by forking another child process to execute the system command?

Here is how I'm handling the interrupt now:

$SIG{'INT'} = 'stop_child'; sub stop_child{ print "Recieved stop signal.\n"; exit; }

Replies are listed 'Best First'.
Re: Ensuring signal receipt under Linux
by chrism01 (Friar) on Jan 24, 2006 at 23:09 UTC
    You could use your sigtrap fn to record the fact (in a global/pkg var) that the sig was received, then when convenient, use the perl built in 'kill' to send/fwd the prev received sig to whichever process.
    It's not quite clear from your qn whether the child fork completes ever, or whether you mean when the shelled-out call completes...
    Remember to clear the pkg var when you do deliver the sig.
    Cheers
    Chris