//---------------------------------------------------------------- // mysignal.cpp // // This demo shows a use of the 'signal()' library-function. // After delivering five 'SIGINT' signals the program exits. // A 'SIGINT' signal is issued when a user hits . // // programmer: ALLAN CRUSE // written on: 16 SEP 2004 //---------------------------------------------------------------- #include // for printf() #include // for signal() int done = 0; void upon_signal( int signum ) { static int count = 0; ++count; printf( "#%d: signum=%d\n", count, signum ); if ( count > 4 ) done = 1; } int main( void ) { //---------------------------- // install our signal-handler //---------------------------- signal( SIGINT, upon_signal ); //---------------------------------------------------- // main program-loop (it just checks the 'done' flag) //---------------------------------------------------- while( !done ) { /* useful actions could go here */ }; //------------------------- // shows exit-notification //------------------------- printf( "Quitting\n" ); }