Microsoft KB Archive/67405

INF: Preventing Program from Ending with CTRL+C or CTRL+BREAK PSS ID Number: Q67405 Article last modified on 09-11-1991 PSS database name: O_Os2SDK

1.10 1.21

OS/2

Summary:

If a C program includes the following lines of code

signal(SIGBREAK, SIG_IGN); signal(SIGINT, SIG_IGN);

the program should ignore the keystroke sequences of CTRL+BREAK and CTRL+C. However, this does not happen in full-screen or windowed API programs. Even in Presentation Manager (PM) programs, when the parent program is CMD.EXE in a PM window, and the CMD.EXE window is activated, CTRL+BREAK aborts the PM program even when the PM program has the above mentioned signal statement in it.

More Information:

This problem can be avoided by using the following code fragments:

To prevent termination in a full-screen program, use the following code:

signal(SIGBREAK, SIG_IGN); signal(SIGINT, SIG_IGN);

To prevent termination in both full-screen and PM programs, use the following code:

signal(SIGBREAK, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGTERM, SIG_IGN);

The extra line of code is needed because PM does not receive a CTRL+C message the same way a full-screen program does. Instead, it receives a termination message, which must be intercepted in a different manner (hence the SIGTERM watch).

There is a file in the Software/Data Library named SIGHAN that demonstrates this type of functionality. This sample program can be terminated in a full screen or window only by pressing the ENTER key.

SIGHAN can be found in the Software/Data Library by searching on the word SIGHAN, the Q number of this article, or S12830. SIGHAN was archived using the PKware file-compression utility.

Copyright Microsoft Corporation 1991.