3 #####################################################################
5 # Test for process id return value from open
6 # Ronald Schmidt (The Software Path) RonaldWS@software-path.com
8 #####################################################################
16 if ($^O eq 'dos' || $^O eq 'MacOS') {
17 skip_all("no multitasking");
25 $SIG{PIPE} = 'IGNORE';
27 my $perl = which_perl();
30 # commands run 4 perl programs. Two of these programs write a
31 # short message to STDOUT and exit. Two of these programs
32 # read from STDIN. One reader never exits and must be killed.
33 # the other reader reads one line, waits a few seconds and then
34 # exits to test the waitpid function.
36 @cmd1 = ($perl,'-I../lib','-e',
37 q{$|=1; print qq[first process\n]; sleep 300;});
38 @cmd2 = ($perl,'-I../lib','-e',
39 q{$|=1; print qq[second process\n]; sleep 30;});
40 @cmd3 = ($perl,'-I../lib','-e',
41 "print <>;"); # hangs waiting for end of STDIN
42 @cmd4 = ($perl,'-I../lib','-e',
45 #warn "#$cmd1\n#$cmd2\n#$cmd3\n#$cmd4\n";
48 ok( $pid1 = open(FH1, "-|", @cmd1), 'first process started');
49 ok( $pid2 = open(FH2, "-|", @cmd2), ' second' );
50 ok( $pid3 = open(FH3, "|-", @cmd3), ' third' );
51 ok( $pid4 = open(FH4, "|-", @cmd4), ' fourth' );
53 print "# pids were $pid1, $pid2, $pid3, $pid4\n";
56 $killsig = 1 unless $Config{sig_name} =~ /\bHUP\b/;
58 # get message from first process and kill it
59 chomp($from_pid1 = scalar(<FH1>));
60 is( $from_pid1, 'first process', 'message from first process' );
62 $kill_cnt = kill $killsig, $pid1;
63 is( $kill_cnt, 1, 'first process killed' ) ||
64 print "# errno == $!\n";
66 # get message from second process and kill second process and reader process
67 chomp($from_pid2 = scalar(<FH2>));
68 is( $from_pid2, 'second process', 'message from second process' );
70 $kill_cnt = kill $killsig, $pid2, $pid3;
71 is( $kill_cnt, 2, 'killing procs 2 & 3' ) ||
72 print "# errno == $!\n";
75 # send one expected line of text to child process and then wait for it
76 select(FH4); $| = 1; select(STDOUT);
78 printf FH4 "ok %d - text sent to fourth process\n", curr_test();
80 print "# waiting for process $pid4 to exit\n";
81 $reap_pid = waitpid $pid4, 0;
82 is( $reap_pid, $pid4, 'fourth process reaped' );