#include #include #include #include #include #include #include volatile int dummy; volatile int child_run = 1; /* #define DPRINTF(a...) fprintf(stderr, a) */ #define DPRINTF(a...) do { } while (0) void child_signal_handler (int signum) { child_run = 0; } int main (void) { int child; struct timespec tp = { 5, 0 }; struct sched_param param; param.sched_priority = 5; sched_setscheduler (0, SCHED_FIFO, ¶m); child = fork(); switch (child) { case 0: DPRINTF("Child starts\n"); signal (SIGTERM, child_signal_handler); param.sched_priority = 4; sched_setscheduler (0, SCHED_FIFO, ¶m); for (; child_run;) dummy = dummy + 1; DPRINTF("Child dies\n"); break; case -1: perror ("fork failed"); abort(); break; default: /* sleep (5); */ syscall (__NR_nanosleep, &tp, NULL); kill (child, SIGTERM); break; } return 0; }