#!./perl
BEGIN {
chdir
't'
if
-d
't'
;
require
'./test.pl'
;
set_up_inc(
'../lib'
);
}
plan
tests
=> 10;
watchdog(15, $^O eq
'MSWin32'
?
"alarm"
:
''
);
$| = 1;
$SIG
{PIPE} =
'IGNORE'
;
$SIG
{HUP} =
'DEFAULT'
;
$SIG
{HUP} =
'IGNORE'
if
$^O eq
'interix'
;
my
$perl
= which_perl();
$perl
.=
qq[ "-I../lib"]
;
my
@perl
= ( which_perl(),
"-I../lib"
);
if
($^O eq
'VMS'
) {
$cmd1
=
qq/$perl -e "\$|=1; print qq[first process\\n]; sleep 30;"/
;
$cmd2
=
qq/$perl -e "\$|=1; print qq[second process\\n]; sleep 30;"/
;
}
else
{
@cmd1
= (
@perl
,
"-e"
,
"\$|=1; print qq[first process\\n]; sleep 30;"
);
@cmd2
= (
@perl
,
"-e"
,
"\$|=1; print qq[second process\\n]; sleep 30;"
);
}
$cmd3
=
qq/$perl -e "print <>;"/
;
$cmd4
=
qq/$perl -e "print scalar <>;"/
;
if
($^O eq
'VMS'
) {
ok(
$pid1
=
open
(FH1,
"$cmd1 |"
),
'first process started'
);
ok(
$pid2
=
open
(FH2,
"$cmd2 |"
),
' second'
);
}
else
{
ok(
$pid1
=
open
(FH1,
"-|"
,
@cmd1
),
'first process started'
);
ok(
$pid2
=
open
(FH2,
"-|"
,
@cmd2
),
' second'
);
}
{
no
warnings
'once'
;
ok(
$pid3
=
open
(FH3,
"| $cmd3"
),
' third'
);
}
ok(
$pid4
=
open
(FH4,
"| $cmd4"
),
' fourth'
);
print
"# pids were $pid1, $pid2, $pid3, $pid4\n"
;
my
$killsig
=
'HUP'
;
$killsig
= 1
unless
$Config
{sig_name} =~ /\bHUP\b/;
chomp
(
$from_pid1
=
scalar
(<FH1>));
is(
$from_pid1
,
'first process'
,
'message from first process'
);
$kill_cnt
=
kill
$killsig
,
$pid1
;
is(
$kill_cnt
, 1,
'first process killed'
) ||
print
"# errno == $!\n"
;
chomp
(
$from_pid2
=
scalar
(<FH2>));
is(
$from_pid2
,
'second process'
,
'message from second process'
);
$kill_cnt
=
kill
$killsig
,
$pid2
,
$pid3
;
is(
$kill_cnt
, 2,
'killing procs 2 & 3'
) ||
print
"# errno == $!\n"
;
select
(FH4); $| = 1;
select
(STDOUT);
printf
FH4
"ok %d - text sent to fourth process\n"
, curr_test();
next_test();
print
"# waiting for process $pid4 to exit\n"
;
$reap_pid
=
waitpid
$pid4
, 0;
is(
$reap_pid
,
$pid4
,
'fourth process reaped'
);