You can control how your program responds to signals it receives. To do this, modify the %SIG associative array. This array contains one element for each available signal, with the signal name serving as the subscript for the element.
Below is simple Perl script which demonstrate the way to handle the interrupt signal...
Below is simple Perl script which demonstrate the way to handle the interrupt signal...
Source: cat signal.pl
#!/usr/bin/perl
$SIG{"INT"} = "catch_signal";
while (1){
print "waiting for signal ... press ctl+c to catch the interrupt signal \n";
sleep(1);
}
sub catch_signal {
print "\n Kool, I am able to handle interrupt signal \n";
exit();
}
Output: perl signal.pl
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
^C
Kool, I am able to handle interrupt signal
#!/usr/bin/perl
$SIG{"INT"} = "catch_signal";
while (1){
print "waiting for signal ... press ctl+c to catch the interrupt signal \n";
sleep(1);
}
sub catch_signal {
print "\n Kool, I am able to handle interrupt signal \n";
exit();
}
Output: perl signal.pl
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
waiting for signal ... press ctl+c to catch the interrupt signal
^C
Kool, I am able to handle interrupt signal
0 comments:
Post a Comment