#define _GNU_SOURCE #include #include #include /*------------------------------------------------------------------*/ static void myHandler(int iSig) /* This function is intended to be a handler for signals of various types. Print iSig to stdout. */ { printf("In myHandler with argument %d\n", iSig); } /*------------------------------------------------------------------*/ int main(void) /* Illustrate the signal() function. Note that this program can be exited only by sending it a SIGKILL signal from another terminal. */ { void (*pfRet)(int); pfRet = signal(SIGHUP, myHandler); /* 1 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGINT, myHandler); /* 2 Generated by ^c */ assert(pfRet != SIG_ERR); pfRet = signal(SIGQUIT, myHandler); /* 3 Generated by ^\ */ assert(pfRet != SIG_ERR); pfRet = signal(SIGILL, myHandler); /* 4 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGTRAP, myHandler); /* 5 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGABRT, myHandler); /* 6 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGBUS, myHandler); /* 7 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGFPE, myHandler); /* 8 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGKILL, myHandler); /* 9 Should fail */ assert(pfRet == SIG_ERR); pfRet = signal(SIGUSR1, myHandler); /* 10 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGSEGV, myHandler); /* 11 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGUSR2, myHandler); /* 12 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGPIPE, myHandler); /* 13 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGALRM, myHandler); /* 14 Generated by alarms */ assert(pfRet != SIG_ERR); pfRet = signal(SIGTERM, myHandler); /* 15 Default from kill cmd */ assert(pfRet != SIG_ERR); pfRet = signal(SIGCHLD, myHandler); /* 17 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGCONT, myHandler); /* 18 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGSTOP, myHandler); /* 19 Should fail */ assert(pfRet == SIG_ERR); pfRet = signal(SIGTSTP, myHandler); /* 20 Generated by ^z */ assert(pfRet != SIG_ERR); pfRet = signal(SIGTTIN, myHandler); /* 21 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGTTOU, myHandler); /* 22 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGURG, myHandler); /* 23 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGXCPU, myHandler); /* 24 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGXFSZ, myHandler); /* 25 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGVTALRM, myHandler);/* 26 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGPROF, myHandler); /* 27 For profilers */ assert(pfRet != SIG_ERR); pfRet = signal(SIGWINCH, myHandler);/* 28 */ assert(pfRet != SIG_ERR); pfRet = signal(SIGIO, myHandler); /* 29 */ assert(pfRet != SIG_ERR); // pfRet = signal(SIGPWR, myHandler); /* 30 */ // assert(pfRet != SIG_ERR); pfRet = signal(SIGSYS, myHandler); /* 31 */ assert(pfRet != SIG_ERR); // pfRet = signal(SIGRTMIN, myHandler);/* 32 */ // assert(pfRet != SIG_ERR); // pfRet = signal(SIGRTMIN, myHandler);/* 33 */ // assert(pfRet != SIG_ERR); printf("Entering an infinite loop\n"); for (;;) ; return 0; }