categorized question
QandAEditors
Ctrl^C
INT
sleep
system
die
exit
sigtrap
process
kill
$SIG{INT}
ALRM
I've got a commandline script, and I wanted to do some stuff before ending the program if somebody hit Ctrl^C.
<P>
I'm using ActivePerl and I've tried:
<CODE>
#!/usr/bin/perl -w
use strict;
$SIG{INT}=\&myhand;
sub myhand
{
print "\n caught $SIG{INT}",@_,"\n";
}
print "program started \n";
while(1){sleep 1;}
</CODE>
I need to hit Ctrl^c twice to kill the program.<BR>
If I add exit; or die; at the end of myhand, perl crashes (PERL caused an exception c0000026H in module KERNEL32.DLL at 015f:bff88510.).
<P>
How do I fix this?
<BR>
I've read [perlman:lib:sigtrap] and I've also tried:
<CODE>
use sigtrap 'handler' => \&myhand, 'INT';
sub myhand
{
print "\n caught $SIG{INT}",@_,"\n";
}
print "program started \n";
while(1){sleep 1;}
</CODE>
which should be the same as my first example, but it also doesn't work (same errors as before).
1877