Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disallow Ctrl-C Perl

Tags:

perl

Is there a way to disallow the CtrlC command to stop a script running in Perl.

I am aware of of the $SIG{'INT'} but I wanted to know for a way that if CtrlC is pressed the script would NOT stop no matter what.

At the moment I have:

$SIG{'INT'};
## for loop here

But once the for loop is over, if CtrlC is pressed, the script will stop.

like image 928
Daveid Fred Avatar asked Mar 29 '26 22:03

Daveid Fred


1 Answers

Ignore interrupts completely:

$SIG{'INT'} = 'IGNORE'; 

Alternatively, map the interrupt to a different character - DEL maybe; then Control-C no longer generates an interrupt (or any other signal) and is a 'normal' control character.

like image 155
Jonathan Leffler Avatar answered Apr 02 '26 06:04

Jonathan Leffler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!