On Wed, Feb 13, 2008 at 05:15:29PM -0600, Chad Walstrom wrote:
> O.K.  I'm tired of writing BASH scripts.  I've decided to jump wholesale
> into Perl as any good Systems Engineer should, right?  I'm running into
> a bit of a problem: signal handling.
> 
> Let's say I want to run system application SYSAPP_A once for each
> element in LIST_A, and if that were to fail, run SYSAPP_B for that
> element.  If I don't trap for signals, and I try to interrupt the Perl
> script with CTRL-C (SIGINT), it kills either SYSAPP_A or SYSAPP_B and
> then continues on looping over LIST_A elements.
> 
> What I want is for the Perl script to die unconditionally.  So, I try this:
> 
>      $SIG{INT} = sub { die "Um, I'm outta here!\n"; };
> 
> This kind of works, but if I hit CTRL-C during SYSAPP_A's run, it fails
> and SYSAPP_B tries to execute.  SYSAPP_A and SYSAPP_B are each called
> with the "system" built-in.
> 
> What do I need to do to make sure the script dies unconditionally when
> any child also receives an interrupt?

I'm a bit rusty on the signals and I don't have the Stevens[1] handy
but I think you want trap SIGCHLD in the main process and handle the
expiration of the child in an appropriate manner.

Here's what 10 secs of Googling brought up:

   http://www.unix.org.ua/orelly/perl/cookbook/ch16_20.htm

Cheers,
florin

1: http://www.kohala.com/start/apue.html

-- 
Bruce Schneier expects the Spanish Inquisition.
      http://geekz.co.uk/schneierfacts/fact/163
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20080213/9749238c/attachment.pgp