Commit | Line | Data |
---|---|---|
d91d68c1 RS |
1 | #!./perl |
2 | ||
3 | ##################################################################### | |
4 | # | |
5 | # Test for process id return value from open | |
6 | # Ronald Schmidt (The Software Path) RonaldWS@software-path.com | |
7 | # | |
8 | ##################################################################### | |
9 | ||
10 | BEGIN { | |
11 | chdir 't' if -d 't'; | |
20822f61 | 12 | @INC = '../lib'; |
c529f79d CB |
13 | if ($^O eq 'dos') { |
14 | print "1..0 # Skip: no multitasking\n"; | |
15 | exit 0; | |
16 | } | |
d91d68c1 RS |
17 | } |
18 | ||
4d61ec05 | 19 | use Config; |
d27127a1 | 20 | $| = 1; |
d91d68c1 RS |
21 | $SIG{PIPE} = 'IGNORE'; |
22 | ||
23 | print "1..10\n"; | |
24 | ||
34046536 | 25 | $perl = qq[$^X "-I../lib"]; |
d91d68c1 RS |
26 | |
27 | # | |
28 | # commands run 4 perl programs. Two of these programs write a | |
29 | # short message to STDOUT and exit. Two of these programs | |
30 | # read from STDIN. One reader never exits and must be killed. | |
31 | # the other reader reads one line, waits a few seconds and then | |
32 | # exits to test the waitpid function. | |
33 | # | |
d27127a1 SM |
34 | $cmd1 = qq/$perl -e "\$|=1; print qq[first process\\n]; sleep 30;"/; |
35 | $cmd2 = qq/$perl -e "\$|=1; print qq[second process\\n]; sleep 30;"/; | |
d91d68c1 RS |
36 | $cmd3 = qq/$perl -e "print <>;"/; # hangs waiting for end of STDIN |
37 | $cmd4 = qq/$perl -e "print scalar <>;"/; | |
38 | ||
39 | #warn "#$cmd1\n#$cmd2\n#$cmd3\n#$cmd4\n"; | |
40 | ||
41 | # start the processes | |
42 | $pid1 = open(FH1, "$cmd1 |") or print "not "; | |
43 | print "ok 1\n"; | |
44 | $pid2 = open(FH2, "$cmd2 |") or print "not "; | |
45 | print "ok 2\n"; | |
46 | $pid3 = open(FH3, "| $cmd3") or print "not "; | |
47 | print "ok 3\n"; | |
48 | $pid4 = open(FH4, "| $cmd4") or print "not "; | |
49 | print "ok 4\n"; | |
50 | ||
51 | print "# pids were $pid1, $pid2, $pid3, $pid4\n"; | |
52 | ||
4d61ec05 GS |
53 | my $killsig = 'HUP'; |
54 | $killsig = 1 unless $Config{sig_name} =~ /\bHUP\b/; | |
55 | ||
d91d68c1 RS |
56 | # get message from first process and kill it |
57 | chomp($from_pid1 = scalar(<FH1>)); | |
58 | print "# child1 returned [$from_pid1]\nnot " | |
59 | unless $from_pid1 eq 'first process'; | |
60 | print "ok 5\n"; | |
4d61ec05 | 61 | $kill_cnt = kill $killsig, $pid1; |
d91d68c1 RS |
62 | print "not " unless $kill_cnt == 1; |
63 | print "ok 6\n"; | |
64 | ||
65 | # get message from second process and kill second process and reader process | |
66 | chomp($from_pid2 = scalar(<FH2>)); | |
67 | print "# child2 returned [$from_pid2]\nnot " | |
68 | unless $from_pid2 eq 'second process'; | |
69 | print "ok 7\n"; | |
4d61ec05 | 70 | $kill_cnt = kill $killsig, $pid2, $pid3; |
d91d68c1 RS |
71 | print "not " unless $kill_cnt == 2; |
72 | print "ok 8\n"; | |
73 | ||
74 | # send one expected line of text to child process and then wait for it | |
d27127a1 SM |
75 | select(FH4); $| = 1; select(STDOUT); |
76 | ||
d91d68c1 RS |
77 | print FH4 "ok 9\n"; |
78 | print "# waiting for process $pid4 to exit\n"; | |
79 | $reap_pid = waitpid $pid4, 0; | |
80 | print "# reaped pid $reap_pid != $pid4\nnot " | |
34046536 | 81 | unless $reap_pid == $pid4; |
d91d68c1 | 82 | print "ok 10\n"; |