/*-------------------------------------------------------------------*/ /* testsignal.c */ /* The signal system call. */ /*-------------------------------------------------------------------*/ #include #include void mySignalHandler(int iSignal) { printf("In mySignalHandler with argument %d\n", iSignal); /* Reset the signal handler. */ signal(iSignal, mySignalHandler); } int main(int argc, char *argv[]) { signal(SIGHUP, mySignalHandler); signal(SIGINT, mySignalHandler); signal(SIGQUIT, mySignalHandler); signal(SIGILL, mySignalHandler); signal(SIGTRAP, mySignalHandler); signal(SIGIOT, mySignalHandler); signal(SIGEMT, mySignalHandler); signal(SIGFPE, mySignalHandler); signal(SIGKILL, mySignalHandler); /* Has no effect */ signal(SIGBUS, mySignalHandler); signal(SIGSEGV, mySignalHandler); signal(SIGSYS, mySignalHandler); signal(SIGPIPE, mySignalHandler); signal(SIGALRM, mySignalHandler); signal(SIGTERM, mySignalHandler); signal(SIGUSR1, mySignalHandler); signal(SIGUSR2, mySignalHandler); signal(SIGCHLD, mySignalHandler); signal(SIGPWR, mySignalHandler); signal(SIGWINCH, mySignalHandler); signal(SIGURG, mySignalHandler); signal(SIGIO, mySignalHandler); signal(SIGSTOP, mySignalHandler); signal(SIGTSTP, mySignalHandler); signal(SIGCONT, mySignalHandler); signal(SIGTTIN, mySignalHandler); signal(SIGTTOU, mySignalHandler); signal(SIGVTALRM, mySignalHandler); signal(SIGPROF, mySignalHandler); signal(SIGXCPU, mySignalHandler); signal(SIGXFSZ, mySignalHandler); printf("Entering an infinite loop\n"); for (;;) ; return 0; } /* Sample execution: --> gcc -Wall -ansi -pedantic -o testsignal testsignal.c --> testsignal Entering an infinite loop ^CIn mySignalHandler with argument 2 ^ZIn mySignalHandler with argument 24 */ /* Note: Must use "kill -9" command from another terminal to stop. */