H
Henry Law
I have a program which runs in the background, doing its thing. When it
receives a SIGTERM it will tidy up and then exit. In test - running it
from a TTY, either in foreground or background, it behaves as expected.
But when I restart Linux (Fedora Core 4, using 'shutdown -r now') the
code that traps SIGTERM isn't executed, despite the Linxu manual
specifically saying that SIGTERM is passed to running processes. Can
someone who has encountered the problem help me to diagnose it? (I am
aware that it might turn out to be a Linux problem, in which case I'll
take it somewhere else ...!)
Here's the core of the code, called clpm.pl
#! /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;
}
Here's the appropriate bit of the system log when I send signals manually:
Here's where CRON starts the task
Sep 1 16:43:01 neptune crond(pam_unix)[2263]: session opened for user
nfb by (uid=0)
Sep 1 16:43:02 neptune clpm.pl[2264]: starting up
Then I do "kill -TERM 2264" from a TTY and ...
Sep 1 16:43:29 neptune clpm.pl[2264]: Normal signal received
Sep 1 16:43:29 neptune crond(pam_unix)[2263]: session closed for user nfb
... that's where it handles the signal and stops.
But here's the system log when I reboot the machine with the "shutdown"
command:
Sep 1 16:45:02 neptune crond(pam_unix)[2283]: session opened for user
nfb by (uid=0)
Sep 1 16:45:02 neptune clpm.pl[2284]: starting up
... lines deleted
Sep 1 16:45:52 neptune clpm.pl[2284]: Running for 60 seconds
It was definitely running ...
Sep 1 16:46:15 neptune shutdown: shutting down for system reboot
Sep 1 16:46:15 neptune init: Switching to runlevel: 6
Sep 1 16:46:17 neptune xfs[1575]: terminating
Sep 1 16:46:19 neptune nmbd[1595]: [2006/09/01 16:46:19, 0]
nmbd/nmbd.c:terminate(56)
Sep 1 16:46:19 neptune nmbd[1595]: Got SIGTERM: going down...
... etc until the reboot happens. clpm.pl just vanishes!
Perl version is 5.8.6 running on Intel.
receives a SIGTERM it will tidy up and then exit. In test - running it
from a TTY, either in foreground or background, it behaves as expected.
But when I restart Linux (Fedora Core 4, using 'shutdown -r now') the
code that traps SIGTERM isn't executed, despite the Linxu manual
specifically saying that SIGTERM is passed to running processes. Can
someone who has encountered the problem help me to diagnose it? (I am
aware that it might turn out to be a Linux problem, in which case I'll
take it somewhere else ...!)
Here's the core of the code, called clpm.pl
#! /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;
}
Here's the appropriate bit of the system log when I send signals manually:
Here's where CRON starts the task
Sep 1 16:43:01 neptune crond(pam_unix)[2263]: session opened for user
nfb by (uid=0)
Sep 1 16:43:02 neptune clpm.pl[2264]: starting up
Then I do "kill -TERM 2264" from a TTY and ...
Sep 1 16:43:29 neptune clpm.pl[2264]: Normal signal received
Sep 1 16:43:29 neptune crond(pam_unix)[2263]: session closed for user nfb
... that's where it handles the signal and stops.
But here's the system log when I reboot the machine with the "shutdown"
command:
Sep 1 16:45:02 neptune crond(pam_unix)[2283]: session opened for user
nfb by (uid=0)
Sep 1 16:45:02 neptune clpm.pl[2284]: starting up
... lines deleted
Sep 1 16:45:52 neptune clpm.pl[2284]: Running for 60 seconds
It was definitely running ...
Sep 1 16:46:15 neptune shutdown: shutting down for system reboot
Sep 1 16:46:15 neptune init: Switching to runlevel: 6
Sep 1 16:46:17 neptune xfs[1575]: terminating
Sep 1 16:46:19 neptune nmbd[1595]: [2006/09/01 16:46:19, 0]
nmbd/nmbd.c:terminate(56)
Sep 1 16:46:19 neptune nmbd[1595]: Got SIGTERM: going down...
... etc until the reboot happens. clpm.pl just vanishes!
Perl version is 5.8.6 running on Intel.