#!perl
use strict;
use warnings;
$SIG{'HUP'}=sub {
print "Got a HUP signal\n";
};
$SIG{'TERM'}=sub {
print "Got a TERM signal\n";
};
open my $f,'>','pid.txt' or die "Could not write pid.txt: $!";
print $f "$$\n";
close $f;
$|=1;
print "Waiting to be killed\n";
while (1) {
print '.';
sleep 30;
}
####
#!perl
use warnings;
use strict;
open my $f,'<','pid.txt' or die "Start killme.pl first";
my $pid=<$f>;
close $f;
for my $sig (qw( HUP TERM KILL )) {
print "Sending $sig ...\n";
kill($sig,$pid);
sleep 2;
}
####
/home/foken>perl killme.pl
Waiting to be killed
.Got a HUP signal
.Got a TERM signal
.Killed
/home/foken>
####
/home/foken>perl killer.pl
Sending HUP ...
Sending TERM ...
Sending KILL ...
/home/foken>
####
F:\>perl killme.pl
Waiting to be killed
.
F:\>
####
F:\>perl killer.pl
Sending HUP ...
Sending TERM ...
Sending KILL ...
F:\>
####
F:\>perl killme.pl
Waiting to be killed
.
F:\>
####
F:\>perl killer.pl
Sending TERM ...
Sending KILL ...
F:\>