#include #include #include #include #include int main (int argc, char **argv) { int test_case_count = argc < 2 ? 10000: atoi (argv[1]); int delay_in_nanoseconds = argc < 3 ? 1000 : atoi (argv[2]); int i; for (i = 0; i < test_case_count; i++) { pid_t p = vfork (); int ok = 0; int volatile child_status = 0; if (p < 0) { perror ("vfork"); return 2; } if (p == 0) { struct timespec timeout; timeout.tv_sec = 0; timeout.tv_nsec = delay_in_nanoseconds; pselect (0, 0, 0, 0, &timeout, 0); _exit (child_status); } if (p > 0) { int status; child_status = 1; if (waitpid (p, &status, 0) == p && WIFEXITED (status) && status == 0) ok = 1; if (!ok) { printf ("vfork bug detected\n"); return 1; } } } return 0; }