G
Glenn
Given the following simple script:
#!/usr/bin/perl -w --
my $terminate = 0;
my $failed = 0;
sub print_signal {
my $signame = shift;
$terminate = 1;
die "got a SIG$signame signal\n";
}
$SIG{INT} = \&print_signal;
$SIG{QUIT} = \&print_signal;
$SIG{TERM} = \&print_signal;
open PIPE, '|-', "sleep 30";
print PIPE "nighty night\n";
$failed |= ! close PIPE;
print "OS error: $!\n";
print "Child error: $?\n";
if (!$terminate) {
print "sleeping after PIPE handling ...\n";
sleep 30;
}
print "terminated by signal\n" if $terminate;
print "failed: $failed\n";
Why is the signal hander not called if I interrupt the script with
SIGINT or SIGQUIT while the PIPE is open? I don't see this behavior
documented anywhere. I expect the %SIG settings to be obeyed as
documented, both during and after the PIPE processing.
Here's the complete behavior, in detail, when the signal is sent while
the PIPE i/o is underway. In each case, I run the script in a shell,
in the foreground.
SIGINT from keyboard => kills PIPE i/o but does not call signal
handler
SIGQUIT from keyboard => kills PIPE i/o but does not call signal
handler
SIGINT from another terminal => has no effect whatsoever
SIGQUIT from another terminal => has no effect whatsoever
SIGTERM from another terminal => signal handler is called
Why is there any difference at all depending on where the signal comes
from, and on what signal is sent?
How do we get these blatant failures documented in the Perl manual?
Note that the signal handlers are clearly still in play after the PIPE
i/o is killed, because a signal sent from any source during the
script's own later sleep() call (either SIGINT, SIGQUIT, or SIGTERM)
does kill the script.
Under this circumstance, how do I get a reliable indication that a
signal was sent (and not just that the PIPE handling failed for quite
possibly some other reason)?
I'm using Perl 5.8.8 for my testing.
#!/usr/bin/perl -w --
my $terminate = 0;
my $failed = 0;
sub print_signal {
my $signame = shift;
$terminate = 1;
die "got a SIG$signame signal\n";
}
$SIG{INT} = \&print_signal;
$SIG{QUIT} = \&print_signal;
$SIG{TERM} = \&print_signal;
open PIPE, '|-', "sleep 30";
print PIPE "nighty night\n";
$failed |= ! close PIPE;
print "OS error: $!\n";
print "Child error: $?\n";
if (!$terminate) {
print "sleeping after PIPE handling ...\n";
sleep 30;
}
print "terminated by signal\n" if $terminate;
print "failed: $failed\n";
Why is the signal hander not called if I interrupt the script with
SIGINT or SIGQUIT while the PIPE is open? I don't see this behavior
documented anywhere. I expect the %SIG settings to be obeyed as
documented, both during and after the PIPE processing.
Here's the complete behavior, in detail, when the signal is sent while
the PIPE i/o is underway. In each case, I run the script in a shell,
in the foreground.
SIGINT from keyboard => kills PIPE i/o but does not call signal
handler
SIGQUIT from keyboard => kills PIPE i/o but does not call signal
handler
SIGINT from another terminal => has no effect whatsoever
SIGQUIT from another terminal => has no effect whatsoever
SIGTERM from another terminal => signal handler is called
Why is there any difference at all depending on where the signal comes
from, and on what signal is sent?
How do we get these blatant failures documented in the Perl manual?
Note that the signal handlers are clearly still in play after the PIPE
i/o is killed, because a signal sent from any source during the
script's own later sleep() call (either SIGINT, SIGQUIT, or SIGTERM)
does kill the script.
Under this circumstance, how do I get a reliable indication that a
signal was sent (and not just that the PIPE handling failed for quite
possibly some other reason)?
I'm using Perl 5.8.8 for my testing.