Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Answer: How do I trap $SIG{INT} ( sigint aka Ctrl^c )?

( #93005=categorized answer: print w/ replies, xml ) Need Help??

Q&A > programs and processes > How do I trap $SIG{INT} ( sigint aka Ctrl^c )? contributed by crazyinsomniac

Basically you need to kill yourself (the process).

#!/usr/bin/perl -w use sigtrap 'handler' => \&myhand, 'INT'; # equivalent to $SIG{INT}=\&myhand; # use strict; # kill 6 doesn't work under strict under IndigoPerl for some reason sub myhand { print "\n caught $SIG{INT}",@_,"\n"; kill 6, $$; # ABRT = 6 # $$ is the pid of the current process } print "program started \n"; while(1) { select(undef,undef,undef,0.25);}

Also check out perlvar(for $$), perlipc and How do I trap control characters/signals?.
kill 6 is the equivalent of kill ABRT (thanks Vynce).

Comment on Answer: How do I trap $SIG{INT} ( sigint aka Ctrl^c )?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2015-07-04 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls