Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Force 2 'ctrl-c's to kill program

by ww (Bishop)
on Feb 11, 2013 at 17:44 UTC ( #1018201=note: print w/ replies, xml ) Need Help??


in reply to Force 2 'ctrl-c's to kill program

TIMTOWTDI

Alternate approach; closer to OP's original (and a surprise to me that it appears to work!)

#!/usr/bin/perl use 5.016; use warnings; use strict; my $prev_ctrlc = 0; if( ($prev_ctrlc == 0) || ($prev_ctrlc == 1) ) { $SIG{'INT'} = \&control_c_observed; sleep 1; for (1..1e3) { say "\t nothing yet"; sleep 2; } } sub control_c_observed { if ($prev_ctrlc == 0) { print "Second ctrl-c within 2 seconds required\n"; $prev_ctrlc = 1; } else { $prev_ctrlc++; } if ($prev_ctrlc == 2 ) { say "OK, that's two of 'em!"; exit; } }

Sample run:

C:\>C:\SQLite\1018190.pl nothing yet nothing yet nothing yet # single tap here Second ctrl-c within 2 seconds required nothing yet nothing yet # double tap here OK, that's two of 'em! C:\>

The sleep's could annoy your users, as they might seem like the machine is (briefly) locking up.


If you didn't program your executable by toggling in binary, it wasn't really programming!


Comment on Re: Force 2 'ctrl-c's to kill program
Select or Download Code
Re^2: Force 2 'ctrl-c's to kill program
by Anonymous Monk on Feb 12, 2013 at 09:45 UTC
    Agreed on sleep. I need to stop using it and start remembering time instead. Cheers

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018201]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2014-09-24 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (244 votes), past polls