/* Count the number of busy loops we can do in 0.1sec. */ #include #include #include #include #include int interrupt = 0; void handler(int signal) { interrupt = 1; } int main(void) { if (fork() != 0) { signal(SIGALRM, handler); while(1) { long long counter = 0; interrupt = 0; while (!interrupt) counter++; printf("%9llu ", counter); fflush(stdout); } } else { int pid = getppid(); while (1) { usleep(100000); /* Wake up parent at 10Hz */ kill(pid, SIGALRM); } } }