Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I trap or ignore keyboard interrupts like control-C?
How can I trap or ignore keyboard interrupts like control-C?
✍: Guest
The basic step is to call signal, either as
#include <signal.h>
signal(SIGINT, SIG_IGN);
to ignore the interrupt signal, or as
extern void func(int);
signal(SIGINT, func);
to cause control to transfer to function func on receipt of an interrupt signal.
On a multi-tasking system such as Unix, it's best to use a slightly more involved technique:
extern void func(int);
if(signal(SIGINT, SIG_IGN) != SIG_IGN)
signal(SIGINT, func);
The test and extra call ensure that a keyboard interrupt typed in the foreground won't inadvertently interrupt a program running in the background (and it doesn't hurt to code calls to signal this way on any system).
On some systems, keyboard interrupt handling is also a function of the mode of the terminal-input subsystem; On some systems, checking for keyboard interrupts is only performed when the program is reading input, and keyboard interrupt handling may therefore depend on which input routines are being called (and whether any input routines are active at all). On MS-DOS systems, setcbrk or ctrlbrk functions may also be involved.
2015-03-06, 1148👍, 0💬
Popular Posts:
How To Change the Password of Another User Account? - MySQL FAQs - Managing User Accounts and Access...
Where Do You Download JUnit? Where do I download JUnit? I don't think anyone will ask this question ...
What Is a TD Tag/Element? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells A "td" elemen...
How to measure functional software requirement specification (SRS) documents? Well, we need to defin...
How To Enter Binary Numbers in SQL Statements? - MySQL FAQs - Introduction to SQL Basics If you want...