Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find that which signal is received in perl?

Tags:

signals

perl

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.

like image 912
sat Avatar asked May 17 '12 10:05

sat


Video Answer


1 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";
}
like image 180
Joni Avatar answered Oct 22 '22 16:10

Joni