3 # tests for both real and emulated fork()
11 unless ($Config::Config{d_fork} or $Config::Config{d_pseudofork});
14 skip_all('fork/status problems on MPE/iX')
19 run_multiple_progs('', \*DATA);
27 if ($result = (kill 9, $cid)) {
31 print "not ok 2 $result\n";
33 sleep 1 if $^O eq 'MSWin32'; # avoid WinNT race bug
47 print "not " unless kill 'INT', $cid;
51 # XXX On Windows the default signal handler kills the
52 # XXX whole process, not just the thread (pseudo-process)
53 $SIG{INT} = sub { exit };
65 print "iteration $i start\n";
69 print "iteration $i parent\n";
72 print "iteration $i child\n";
76 print "pid $$ failed to fork\n";
79 while ($i++ < 3) { do { forkit(); }; }
106 ? (print("parent\n"),sleep(1))
107 : (print("child\n"),exit) ;
115 ? (print("parent\n"),exit)
116 : (print("child\n"),sleep(1)) ;
161 foreach my $c (1,2,3) {
170 while (wait() != -1) { print "waited\n" }
187 ? print($Config{osname} eq $^O)
188 : print($Config{osname} eq $^O) ;
197 ? do { require Config; print($Config::Config{osname} eq $^O); }
198 : do { require Config; print($Config::Config{osname} eq $^O); }
206 my $cwd = cwd(); # Make sure we load Win32.pm while "../lib" still works.
213 print cwd() =~ /\Q$dir/i ? "ok 1 parent" : "not ok 1 parent";
222 print cwd() =~ /\Q$dir/i ? "ok 1 child" : "not ok 1 child";
234 if ($^O eq 'MSWin32' || $^O eq 'NetWare') {
235 $getenv = qq[$^X -e "print \$ENV{TST}"];
238 $getenv = qq[$^X -e 'print \$ENV{TST}'];
243 print "parent before: " . `$getenv`;
245 print "parent after: " . `$getenv`;
248 print "child before: " . `$getenv`;
250 print "child after: " . `$getenv`;
263 print "parent got $?"
277 print "parent got $?"
295 parent died at - line 2.
296 child died at - line 5.
299 eval { die "parent died" };
303 eval { die "child died" };
308 parent died at - line 2.
309 child died at - line 6.
311 if (eval q{$pid = fork}) {
312 eval q{ die "parent died" };
316 eval q{ die "child died" };
321 parent died at (eval 2) line 1.
322 child died at (eval 2) line 1.
329 # XXX In emulated fork(), the child will not execute anything after
330 # the BEGIN block, due to difficulties in recreating the parse stacks
331 # and restarting yyparse() midstream in the child. This can potentially
332 # be overcome by treating what's after the BEGIN{} as a brand new parse.
338 sub pipe_to_fork ($$) {
341 pipe($child, $parent) or die;
343 die "fork() failed: $!" unless defined $pid;
344 close($pid ? $child : $parent);
348 if (pipe_to_fork('PARENT','CHILD')) {
350 print PARENT "pipe_to_fork\n";
355 while (<CHILD>) { print; }
360 sub pipe_from_fork ($$) {
363 pipe($parent, $child) or die;
365 die "fork() failed: $!" unless defined $pid;
366 close($pid ? $child : $parent);
370 if (pipe_from_fork('PARENT','CHILD')) {
372 while (<PARENT>) { print; }
377 print CHILD "pipe_from_fork\n";
388 print "forked first kid\n";
389 print "waitpid() returned ok\n" if waitpid($pid,0) == $pid;
392 print "first child\n";
396 print "forked second kid\n";
397 print "wait() returned ok\n" if wait() == $pid;
400 print "second child\n";
407 waitpid() returned ok
412 pipe(RDR,WTR) or die $!;
414 die "fork: $!" if !defined $pid;
417 print WTR "STRING_FROM_CHILD\n";
421 chomp(my $string_from_child = <RDR>);
423 print $string_from_child eq "STRING_FROM_CHILD", "\n";
429 # [perl #39145] Perl_dounwind() crashing with Win32's fork() emulation
430 sub { @_ = 3; fork ? die "1\n" : die "1\n" }->(2);
436 # [perl #72604] @DB::args stops working across Win32 fork
440 print "waitpid() returned ok\n" if waitpid($pid,0) == $pid;
445 print "child: called as [$c[3](", join(',',@DB::args), ")]\n";
452 child: called as [main::f(foo,bar)]
453 waitpid() returned ok
455 # Windows 2000: https://rt.cpan.org/Ticket/Display.html?id=66016#txn-908976
456 system $^X, "-e", "if (\$pid=fork){sleep 1;kill(9, \$pid)} else {sleep 5}";
461 # Windows 7: https://rt.cpan.org/Ticket/Display.html?id=66016#txn-908976
462 system $^X, "-e", "if (\$pid=fork){kill(9, \$pid)} else {sleep 5}";