Is it possible for a console application to deny closing with CTRL + C?

3

0

When I run a console application (either a .bat or a .exe console application made with a language like Cpp or C# for example) in a shell, I can hit Control + C to stop the operation.

Is it possible for a console application to be immune to Control + C?

P. Ktinos

Posted 2016-12-04T17:34:08.750

Reputation: 183

The python interpeter intercepts Control+C. – timotree – 2016-12-04T18:14:21.337

This may be interesting https://msdn.microsoft.com/en-us/library/windows/desktop/ms682541(v=vs.85).aspx

– Dave – 2016-12-04T19:52:00.830

Answers

1

Yes, it's possible. There are two ways to do this that I know of.

Method #1: The console application contains a signal handler to prevent the Control+C and other terminating signals. Here's one way to do this.

Method #2: You run the program inside of another program that contains the signal handler. I have an example of a signal catcher here.

MD XF

Posted 2016-12-04T17:34:08.750

Reputation: 214

Oh, I didn't think it was possible to catch the signals thrown by ctrl+C. Always thought it raised sigstop. – P. Ktinos – 2016-12-04T19:57:14.230