/* $begin counterprob */ #include "csapp.h" int counter = 0; void handler(int sig) { counter++; printf("hand_counter=%d\n", counter); sleep(1); /* do some work in the handler */ return; } int main() { int i, pid, status; Signal(SIGUSR2, handler); pid = Fork(); if (pid == 0) { /* child */ for (i = 0; i < 5; i++) { Kill(getppid(), SIGUSR2); sleep(1); printf("sent SIGUSR2 to parent\n"); } exit(0); } Wait(&status); printf("counter=%d\n", counter); exit(0); } /* $end counterprob */