/* * internal.c - A program that responds to interally * generated events (SIGALARM signals) */ #include #include #include #include #include "safe_printf.h" int beeps = 0; /* SIGALRM handler */ void handler(int sig) { safe_printf("BEEP\n"); if (++beeps < 5) alarm(1); else { safe_printf("BOOM!\n"); exit(0); } } int main() { signal(SIGALRM, handler); alarm(1); /* send SIGALRM in 1 second */ while (1) { continue; /* handler returns here */ } }