#define _GNU_SOURCE #include #include #include #include #include #include int main(void) { pid_t pid; int status; size_t i, count; unsigned long max = 300000, first; struct timespec ts = { .tv_nsec = 1 }; char* const argv[] = {"/bin/tail", "-a", NULL}; for (i = 0; i < 42000; ++i) { for (count = first = 0, ts.tv_nsec = 1; ts.tv_nsec < max && count < 10; ts.tv_nsec += 1) { if ((pid = fork())) { if (pid < 0) continue; nanosleep(&ts, NULL); kill(pid, SIGKILL); if (waitpid(pid, &status, 0) != pid) continue; if (WIFSIGNALED(status) && WTERMSIG(status) == 9) { continue; } else if (WIFEXITED(status) && WEXITSTATUS(status) == 1) { count++; if (!first) first = ts.tv_nsec; } else printf("%lu: %x\n", ts.tv_nsec, status); } else { close(STDOUT_FILENO); close(STDERR_FILENO); execve("/bin/tail", argv, NULL); _exit(2); } } if (max < ts.tv_nsec) max = ts.tv_nsec; if (count < 10) max += 5000; printf("break at %lu (max: %lu) count %lu (first at %lu)\n", ts.tv_nsec, max, count, first); } return 0; }