Daveid Fred
Daveid Fred

Reputation: 419

Disallow Ctrl-C 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.

Upvotes: 2

Views: 796

Answers (2)

Jonathan Leffler
Jonathan Leffler

Reputation: 754590

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.

Upvotes: 9

Noufal Ibrahim
Noufal Ibrahim

Reputation: 72815

Catch SIGINT and simply ignore it. Would that not work? What's wrong with that? I didn't quite understand your meaning by saying that you're aware of what $SIG{'INT'} is.

Upvotes: 1

Related Questions