On Linux, with Perl 5.8.0 (but on many another combination
of OS and Perl version) the following code doesn't do what I expect:
#!/usr/bin/perl
use POSIX qw(pause);
use strict;
my $ppid=$$;
$SIG{HUP}=sub {return};
my $pid=fork;
if ($pid){
pause;
print "parent woke up\n";
waitpid $pid,0;
print "parent reaped child\n";
} else {
die "fork error $!" if (!defined $pid);
sleep 2; # what can I say, it works.
print "child is about to signal parent (at $ppid)\n";
# `kill -1 $ppid`;
my $cnt=kill,1,$ppid;
print "child signaled $cnt process(es)\n";
print "child about to exit\n";
exit;
}
This program outputs the following:
hbo@owen|1337> perl test
child is about to signal parent (at 24421)
child signaled 0 process(es)
child about to exit
A 'kill -1 $ppid' from the shell gets the program unstuck.
If I comment out the internal kill function and subsequent print statement, and uncomment the back-tick kill, it works as I'd like:
hbo@owen|1338> perl test
child is about to signal parent (at 24428)
parent woke up
child about to exit
parent reaped child
I've never gotten Perl's built-in kill to work for me. Any ideas?