projects
/
urisagit/Perl-Docs.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
blame
|
history
|
raw
|
HEAD
changes
[urisagit/Perl-Docs.git]
/
t
/
foo.pl
1
#!/usr/local/bin/perl
2
3
4
sub pipe_from_fork ($) {
5
my $parent = shift;
6
pipe $parent, my $child or die;
7
my $pid = fork();
8
die "fork() failed: $!" unless defined $pid;
9
if ($pid) {
10
close $child;
11
}
12
else {
13
close $parent;
14
open(STDOUT, ">&=" . fileno($child)) or die;
15
}
16
$pid;
17
}
18
19
if (pipe_from_fork('BAR')) {
20
# parent
21
while (<BAR>) { print; }
22
close BAR;
23
}
24
else {
25
# child
26
print "pipe_from_fork\n";
27
close STDOUT;
28
exit(0);
29
}
30