#include #include #include #include #include #include "signal-helper.h" int beeps = 0; void sigalrm_handler(int sig) { // SIGALRM handler safe_printf("BEEP\n"); if (++beeps < 5) { alarm(1); } else { safe_printf("DING DING!\n"); exit(0); } } int main() { // install the handler if (Signal(SIGALRM, sigalrm_handler) == SIG_ERR) { unix_error("signal error"); } alarm(1); /* send SIGALRM in 1 second */ while (1) { } return 0; }