Debian Codegraph @

t/fork.t

raw
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More;
5 use Tk;
6
7 if ($^O eq 'MSWin32' || $^O eq 'cygwin') {
8 print "1..0 # skip No real fork on Windows-like systems\n";
9 exit;
10 }
11
12 plan tests => 3;
13
14 my $mw = tkinit;
15 $mw->geometry("+10+10");
16 ok Tk::IsParentProcess(), 'This is the parent';
17 pipe(my($rdr,$wtr));
18 if (fork == 0) {
19 close $rdr;
20 select $wtr; $| = 1; select STDOUT; # autoflush, needed because of POSIX::_exit
21 print $wtr (Tk::IsParentProcess() ? 'parent' : 'child'), "\n";
22 print "# Child $$\n";
23 require POSIX;
24 POSIX::_exit(0);
25 }
26 else {
27 close $wtr;
28 print "# Parent $$\n";
29 }
30 my $child_result = <$rdr>;
31 like $child_result, qr{^child}, 'Child is not the parent process';
32 # Pause to allow child to exit, and to collect the
33 select undef, undef, undef, 0.5;
34 $mw->update;
35 pass 'No segfaults';
36
37 __END__