/* alarm2.c Just like alarm.c , but without the csapp wrappers, and with explicit C library headers instead. Note the use of "static" here. What does that do? */ #include /* printf */ #include /* alarm */ #include /* exit */ #include /* signal, SIGALRM */ void handler(int sig){ static int beeps = 0; printf("BEEP\n"); if (++beeps < 5){ alarm(1); /* Next SIGALRM will be delivered in 1 second */ } else { printf("BOOM!\n"); exit(0); } } int main(){ signal(SIGALRM, handler); /* install SIGALRM handler */ alarm(1); /* Next SIGALRM will be delivered in 1s */ while (1){ ; /* Signal handler returns control here each time */ } exit(0); }