#include #include #include void ouch(int sig) { printf("Ouch! Got signal %d\n", sig); // danger call printf in signal handler // try without the next line and kill from another window see signals.h to see what happened if (sig==SIGINT) signal(SIGINT, SIG_DFL); // restore the default } void wakeup(int sig) { printf("Wake up!!\n"); printf("zzzzzzzzzzzzzzzz\n"); } int main() { printf("PID: %d\n", getpid()); signal(SIGHUP, ouch); // 1 signal(SIGINT, ouch); // 2 signal(SIGQUIT, ouch); // 3 signal(SIGABRT, ouch); // 6 signal(SIGKILL, ouch); // 9 signal(SIGALRM, wakeup); // 14 // signal(SIGINT, SIG_IGN); // ignore the alarm forever for (int i=0; i<100; i++) { printf("tick - "); fflush(stdout); sleep(1); printf("tock\n"); fflush(stdout); sleep(1); } return 0; }