H
Henry Law
I'm trying to debug a Perl problem whose symptoms are that a running
Perl process either doesn't receive, or fails inexplicably to handle, a
SIGTERM sent from the OS during shutdown (Linux Fedora Core 4, if it
matters). One way to find out whether it's a Perl problem or an OS
problem is for me to run a program in some other language and see if it
receives SIGTERM when Linux shuts down (as it's supposed to, according
to the manuals).
I have written C in my time but I'm very rusty, and I'm hoping that
someone could either sketch out, or point me at, some skeleton code
which I could then perfect to do the job. I'll be OK with debugging and
so forth, but I know that I could spend ages rootling around looking for
the right #include statements and constants for the signalling and the
syslogging.
All I need is a program that can be run in the background (CRON) and
will syslog a message when it gets a SIGTERM. The original Perl program
is this (which most C programmers will understand, I hope).
#! /usr/bin/perl
use strict;
use warnings;
use Sys::Syslog;
use sigtrap 'handler' => \&terminate, 'normal-signals';
my $loop_count = 0;
my $timer = 0;
my $sleep_size = 10;
my $loop_size = 6;
openlog 'clpm.pl', 'cons,pid', 'user';
syslog 'info', 'starting up';
while (1) {
while (++$loop_count < $loop_size) {
sleep $sleep_size;
}
$timer += $loop_count*$sleep_size;
$loop_count = 0;
syslog 'info', "Running for $timer seconds";
}
syslog 'info', 'How did we get here?';
sub terminate {
syslog 'info', 'Normal signal received';
exit 0;
}
All help gratefully received.
Perl process either doesn't receive, or fails inexplicably to handle, a
SIGTERM sent from the OS during shutdown (Linux Fedora Core 4, if it
matters). One way to find out whether it's a Perl problem or an OS
problem is for me to run a program in some other language and see if it
receives SIGTERM when Linux shuts down (as it's supposed to, according
to the manuals).
I have written C in my time but I'm very rusty, and I'm hoping that
someone could either sketch out, or point me at, some skeleton code
which I could then perfect to do the job. I'll be OK with debugging and
so forth, but I know that I could spend ages rootling around looking for
the right #include statements and constants for the signalling and the
syslogging.
All I need is a program that can be run in the background (CRON) and
will syslog a message when it gets a SIGTERM. The original Perl program
is this (which most C programmers will understand, I hope).
#! /usr/bin/perl
use strict;
use warnings;
use Sys::Syslog;
use sigtrap 'handler' => \&terminate, 'normal-signals';
my $loop_count = 0;
my $timer = 0;
my $sleep_size = 10;
my $loop_size = 6;
openlog 'clpm.pl', 'cons,pid', 'user';
syslog 'info', 'starting up';
while (1) {
while (++$loop_count < $loop_size) {
sleep $sleep_size;
}
$timer += $loop_count*$sleep_size;
$loop_count = 0;
syslog 'info', "Running for $timer seconds";
}
syslog 'info', 'How did we get here?';
sub terminate {
syslog 'info', 'Normal signal received';
exit 0;
}
All help gratefully received.