#include #include #include #include #include #include #include #include #include void die(const char* msg) { fprintf(stderr, "ERR!! %s: %s\n", msg, strerror(errno)); exit(-1); } char thread_stack[4096]; int thread_func(void *arg) { execl("/bin/true", NULL); die("exec"); return 0; } void proc_func(void) { int pid; for (;;) if ((pid = fork())) { if (pid != waitpid(pid, NULL, 0)) die("wait4"); } else { struct sigevent sigev = {}; struct itimerspec itsp = {}; timer_t tid; sigev.sigev_signo = SIGRTMIN; sigev.sigev_notify = SIGEV_SIGNAL; if (timer_create(CLOCK_MONOTONIC, &sigev, &tid) == -1) die("timer_create"); itsp.it_value. tv_nsec = 1; itsp.it_interval. tv_nsec = 1; if (timer_settime(tid, 0, &itsp, NULL)) die("timer_settime"); if (clone(thread_func, thread_stack + 2048, CLONE_THREAD|CLONE_SIGHAND|CLONE_VM|CLONE_FILES, NULL) < 0) die("clone"); pause(); } } int main(void) { int pn; signal(SIGRTMIN, SIG_IGN); for (pn = 0; pn < 16; ++pn) if (!fork()) proc_func(); pause(); return 0; }