I wrote a simple program for handling some of the signals. My Program is,
#!/usr/bin/perl
use strict;
use warnings;
$SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler;
sub signal_handler
{
print " ".localtime()." Handled the signal\n";
};
while(1)
{
sleep(1);
}
What are the signals are specified in the %SIG
hash that corresponds signal handler
will be called at the time of receiving the signal.
I declared one signal handler for three signals.
I want to find which signal is received.
In C
, It will give the signal number by the signal handler arguments itself.
Example,
void sig_handler(int signo);
I don't know in perl.I try to find that.But,I didn't find any answers.
The signal name (INT, TERM, etc) is passed as parameter to the signal handler. You could write for example:
sub signal_handler
{
my $signal = shift;
print " ".localtime()." Handled the signal $signal\n";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With