/* Programmer: Greg Perkins Program: sigint.c Class: CS 73 - C/UNIX Due: April 28, 1998 This program demonstrates the use of signal to trap keyboard interrupts from the terminal. The program is a modification of the one found on page 295; it counts/treats the interrupts (^\) and (^C) differently. To stop execution of the program, the user can suspend execution (^Z) and then kill the program externally. */ #include #include main() { void cnt(int sig); signal(SIGINT, cnt); signal(SIGQUIT, cnt); printf("Begin counting INTERRUPTs\n"); for (;;); /* infinite loop */ } void cnt(int sig) { static int Ccount=0; static int Qcount=0; if (sig == SIGINT) Ccount++; else Qcount++; printf("Total INTERRUPTs received: %5d - ^C %5d - ^\\\n", Ccount,Qcount); }