This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / t / io / closepid.t
CommitLineData
e9d373c4
TC
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
624c42e2
N
5 require "./test.pl";
6 set_up_inc('../lib');
e9d373c4
TC
7}
8
e9d373c4
TC
9plan tests => 3;
10watchdog(10, $^O eq 'MSWin32' ? "alarm" : '');
11
12use Config;
13$| = 1;
14$SIG{PIPE} = 'IGNORE';
af1f7e28
TC
15# work around a shell set to ignore HUP
16$SIG{HUP} = 'DEFAULT';
e9d373c4
TC
17$SIG{HUP} = 'IGNORE' if $^O eq 'interix';
18
19my $perl = which_perl();
e9d373c4
TC
20
21my $killsig = 'HUP';
22$killsig = 1 unless $Config{sig_name} =~ /\bHUP\b/;
23
24SKIP:
25{
26 skip("Not relevant to $^O", 3)
27 if $^O eq "MSWin32" || $^O eq "VMS";
28 skip("only matters for waitpid or wait4", 3)
29 unless $Config{d_waitpid} || $Config{d_wait4};
30 # [perl #119893]
31 # close on the original of a popen handle dupped to a standard handle
32 # would wait4pid(0, ...)
33 open my $savein, "<&", \*STDIN;
af1f7e28 34 my $pid = open my $fh1, "-|", $perl, "-e", "sleep 50";
e9d373c4
TC
35 ok($pid, "open a pipe");
36 # at this point PL_fdpids[fileno($fh1)] is the pid of the new process
37 ok(open(STDIN, "<&=", $fh1), "dup the pipe");
38 # now PL_fdpids[fileno($fh1)] is zero and PL_fdpids[0] is
39 # the pid of the process created above, previously this would block
40 # internally on waitpid(0, ...)
41 ok(close($fh1), "close the original");
42 kill $killsig, $pid;
43 open STDIN, "<&", $savein;
44}