in reply to protect children from SIG{INT}
You're right, fork will give you the flexibility you need.
sub slumber { # signal-safe sleep, added my $span = shift; $span -= sleep $span while $span > 0; 1; } $SIG{CHLD} = 'IGNORE'; while (1) { defined( my $cpid = fork ) or warn $! and slumber 5 and next; slumber 5 and next if $cpid; # parent # $SIG{INT} = $SIG{HUP} = sub {}; # child $SIG{INT} = $SIG{HUP} = 'IGNORE'; # child exec qw(rsync -a rsync://blah.example.com/foo foo); die 'exec failed'; }
The empty handlers for keyboard interrupt and terminal hangup are both needed to isolate the child. The OS will send a HUP to the child when the parent exits, and the default handler is for the child to exit, too. Untested.
Update: Added slumber function to ensure timing and corrected the INT and HUP handler assignment.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: protect children from SIG{INT}
by pileofrogs (Priest) on Nov 18, 2005 at 02:42 UTC | |
|
Re^2: protect children from SIG{INT}
by sgifford (Prior) on Nov 18, 2005 at 02:38 UTC | |
by Zaxo (Archbishop) on Nov 18, 2005 at 09:13 UTC | |
by QM (Parson) on Nov 18, 2005 at 15:12 UTC | |
by sgifford (Prior) on Nov 18, 2005 at 16:18 UTC | |
by pileofrogs (Priest) on Nov 18, 2005 at 16:57 UTC |