cdarke:
Can you point to some documentation? I did a quick search (not very thorough), and haven't found any evidence that the alarm handlers don't survive a fork. The OpenGroup alarm documentation clearly states that pending alarm signals are cleared for the child, and their fork docs state that the child process will have its alarm cleared and any pending alarm reset. So I don't see why the parent using alarm & kill wouldn't work.
I don't have my hands on a Unix box at the moment, but under windows, I get this:
301058@LOU-PC0288 /Work/METABASE
$ perl forktest.pl
nofork: ALARM!
nofork: done...
301058@LOU-PC0288 /Work/METABASE
$ perl forktest.pl a
PID(2560): ALARM!
PID(0): QUITTING!
PID(2560): done...
301058@LOU-PC0288 /Work/METABASE
$ cat forktest.pl
use strict;
use warnings;
my $prefix="nofork";
my $PID;
$SIG{INT} = sub { die "$prefix: QUITTING!\n\n"; };
$SIG{ALRM} = sub { print "$prefix: ALARM!\n\n"; kill 2,$PID if $PID; }
+;
alarm(5);
if (@ARGV) {
# with any argument we fork, o/w we don't
$PID = fork;
$prefix = "PID($PID)";
}
# Wait long enough for alarm to trigger
my $t = time;
while ($t + 10 > time) {
# doze
}
print "$prefix: done...\n\n";
alarm(0);
301058@LOU-PC0288 /Work/METABASE
$
...roboticus
|