#include #include #include /* * ouch -- show how a program can trap the Ctrl-C interrupt signal */ int main() { int i = 0; void ouch(int); signal(SIGINT, ouch); /* call ouch() when I recv SIGINT */ while(1){ printf("hello\n"); sleep(5); i++; if ( i == 6 ){ printf("resetting response to SIGINT to default\n"); signal(SIGINT, SIG_DFL); } } return 0; } void ouch(int n) { static int times = 0; times++; printf(" \aOuch! for time number %d my arg was %d\n",times, n); }