M
monk
Hi all,
Is it safe/sane/common practice to have a program react to every
single POSIX signal there is out there available in the OS?
Some friends have suggested to just stick to the basic ones such as
TSTP and INT. Meaning, tell the program to do something (like an
email alert) if it receives a control-Z or control-C only. But what
about the others?
My fear is that my chronic paranoia might get in the way, thus making
my programs unstable.
At the same time, I don't want to miss any unseen events that may
affect my programs reliability.
Positively, _*any*_ thoughts are welcome.
for example, to see what I mean if confusing above. I don't know if it
matters but I'm using Linux 2.6.x and AIX 5.3 with perl 5.8.2. Thanks
in advance. :
#!/usr/bin/perl
use strict;
use warnings;
#all this does is print "hello world" every 1 second --given a true
condition.
#if *any* signal is received, the status changes to false exiting the
program gracefully.
#my vars
my $signal;
my $status = 1;
my $pid;
my @all_signals;
my $file_handler;
#sub routine handling the signal received
sub signal_handler {
$signal = shift;
$status = 0;
$SIG{$signal} = \&signal_handler;
}
#get all signals available on AIX
#add them up to an array
sub get_all_my_signals {
foreach my $list (sort keys %SIG){
push (@all_signals, $list);
}
}
sub go {
#get all signals available on this OS
get_all_my_signals();
#if any signal is received, change status to zero
#thus exiting the loop.
foreach (@all_signals){
$SIG{$_} = \&signal_handler;
}
#Current process' PID is
$pid = $$;
#writing pid to a file
open ($file_handler, ">", "test.pid");
print $file_handler $pid;
close $file_handler;
while ($status == 1){
print "hello world\n";
sleep 1;
}
print "out of loop. Got signal \$SIG{$signal}\n";
#house keeping
unlink "test.pid" if (-e "test.pid");
exit(0);
}
###done defniing now let's call it
#call it now..
go();
Is it safe/sane/common practice to have a program react to every
single POSIX signal there is out there available in the OS?
Some friends have suggested to just stick to the basic ones such as
TSTP and INT. Meaning, tell the program to do something (like an
email alert) if it receives a control-Z or control-C only. But what
about the others?
My fear is that my chronic paranoia might get in the way, thus making
my programs unstable.
At the same time, I don't want to miss any unseen events that may
affect my programs reliability.
Positively, _*any*_ thoughts are welcome.
for example, to see what I mean if confusing above. I don't know if it
matters but I'm using Linux 2.6.x and AIX 5.3 with perl 5.8.2. Thanks
in advance. :
#!/usr/bin/perl
use strict;
use warnings;
#all this does is print "hello world" every 1 second --given a true
condition.
#if *any* signal is received, the status changes to false exiting the
program gracefully.
#my vars
my $signal;
my $status = 1;
my $pid;
my @all_signals;
my $file_handler;
#sub routine handling the signal received
sub signal_handler {
$signal = shift;
$status = 0;
$SIG{$signal} = \&signal_handler;
}
#get all signals available on AIX
#add them up to an array
sub get_all_my_signals {
foreach my $list (sort keys %SIG){
push (@all_signals, $list);
}
}
sub go {
#get all signals available on this OS
get_all_my_signals();
#if any signal is received, change status to zero
#thus exiting the loop.
foreach (@all_signals){
$SIG{$_} = \&signal_handler;
}
#Current process' PID is
$pid = $$;
#writing pid to a file
open ($file_handler, ">", "test.pid");
print $file_handler $pid;
close $file_handler;
while ($status == 1){
print "hello world\n";
sleep 1;
}
print "out of loop. Got signal \$SIG{$signal}\n";
#house keeping
unlink "test.pid" if (-e "test.pid");
exit(0);
}
###done defniing now let's call it
#call it now..
go();