#include #include #include /* required by exit() */ #include /* required by pause() */ static void sig_usr(int); /* one handler for both signals */ /* static tells that a function or data element is only known within the scope of the current compile. In addition, if you use the static keyword with a variable that is local to a function, it allows the last value of the variable to be preserved between successive calls to that function. http://tigcc.ticalc.org/doc/keywords.html#static */ void err_sys(char * msg) { printf("%s \n", msg); exit(-1); } int main(void) { if (signal(SIGUSR1, sig_usr) == SIG_ERR) err_sys("can't catch SIGUSR1"); if (signal(SIGUSR2, sig_usr) == SIG_ERR) err_sys("can't catch SIGUSR2"); for ( ; ; ) pause(); } static void sig_usr(int signo) { /* argument is signal number */ if (signo == SIGUSR1) printf("received SIGUSR1\n"); else if (signo == SIGUSR2) printf("received SIGUSR2\n"); else err_sys("received unexpected signal"); return; }