#include #include #include #include #include #include volatile unsigned long loop = 10000000; void handler (int n) { if (loop > 0) --loop; } static int child (void) { pid_t ppid = getppid (); sleep (1); while (1) kill (ppid, SIGUSR1); return 0; } int main (int argc, char **argv) { pid_t child_pid; int r; loop = argc > 1 ? strtoul (argv[1], NULL, 10) : 10000000; printf ("expecting to receive %lu signals\n", loop); if ((child_pid = fork ()) == 0) exit (child ()); signal (SIGUSR1, handler); while (loop) sleep (1); r = kill (child_pid, SIGTERM); waitpid (child_pid, NULL, 0); return 0; }