How can I use `pipe` to facilitate interprocess communication in Perl?
- by Shiftbit
Can anyone explain how I can successfully get my processes communicating? I find the perldoc on IPC confusing.
What I have so far is:
$| = 1;
$SIG{CHLD} = {wait};
my $parentPid = $$;
if ($pid = fork();) ) {
if ($pid == 0) {
pipe($parentPid, $$);
open PARENT, "<$parentPid";
while (<PARENT>) {
print $_;
}
close PARENT;
exit();
} else {
pipe($parentPid, $pid);
open CHILD, ">$pid";
or error("\nError opening: childPid\nRef: $!\n");
open (FH, "<list")
or error("\nError opening: list\nRef: $!\n");
while(<FH>) {
print CHILD, $_;
}
close FH
or error("\nError closing: list\nRef: $!\n");
close CHILD
or error("\nError closing: childPid\nRef: $!\n);
} else {
error("\nError forking\nRef: $!\n");
}
First: What does perldoc pipe mean by READHANDLE, WRITEHANDLE?
Second: Can I implement a solution without relying on CPAN or other modules?