/* - Signal handling example - Catch control C - sigaction not used because it is not supported ECED 3403 27 June 16 */ #include "stdafx.h" #include #include #include /* Signal handling software */ #define FALSE 0 #define TRUE 1 int waiting_for_signal; /* T|F - indicates whether ^C detected */ void sigint_hdlr() { /* - Invoked when SIGINT (control-C) is detected - changes state of waiting_for_signal - signal must be reinitialized */ waiting_for_signal = FALSE; signal(SIGINT, (_crt_signal_t) sigint_hdlr); /* Reinitialize SIGINT */ } int main(int argc, char *argv[]) { /* - Mainline - example of loop waiting for sigint */ long loop_count; int i; /* Call signal() - bind sigint_hdlr to SIGINT */ signal(SIGINT, (_crt_signal_t) sigint_hdlr); for (i = 0; i<5; i++) { printf("Starting %d...\n", i); loop_count = 0; waiting_for_signal = TRUE; while (waiting_for_signal) loop_count++; printf("All done %ld\n", loop_count); getchar(); } getchar(); return 0; }