3 unless ($Config{d_fork}) {
4 print "1..0 # Skip: no fork\n";
7 eval 'use POSIX qw(sys_wait_h)';
9 print "1..0 # Skip: no POSIX sys_wait_h\n";
12 eval 'use Time::HiRes qw(time)';
14 print "1..0 # Skip: no Time::HiRes\n";
26 sub NEG1_PROHIBITED () { 0x01 }
27 sub NEG1_REQUIRED () { 0x02 }
31 my $state = NEG1_PROHIBITED;
33 my $child_pid = fork();
35 # Parent receives a nonzero child PID.
40 while ($count++ < $max_count) {
41 my $begin_time = time();
42 my $ret = waitpid( -1, WNOHANG );
43 my $elapsed_time = time() - $begin_time;
45 printf( "# waitpid(-1,WNOHANG) returned %d after %.2f seconds\n",
46 $ret, $elapsed_time );
47 if ($elapsed_time > 0.5) {
48 printf( "# %.2f seconds in non-blocking waitpid is too long!\n",
54 if ($state & NEG1_PROHIBITED) {
56 print "# waitpid should not have returned -1 here!\n";
60 elsif ($ret == $child_pid) {
61 $state = NEG1_REQUIRED;
64 elsif ($state & NEG1_REQUIRED) {
66 print "# waitpid should have returned -1 here\n";
74 print $ok ? "ok 1\n" : "not ok 1\n";
77 # Child receives a zero PID and can request parent's PID with