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
In reply to Re: protect children from SIG{INT}
by Zaxo
in thread protect children from SIG{INT}
by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |