in reply to why?
The close() is important because fork tends to duplicate open filehandles between the parent and child. We take advantage of some of this, though.use IO::Handle; pipe(READER, WRITER); WRITER->autoflush(1); if ($pid = fork) { # if fork returned a PID, this must be the parent close READER; # so the child can use it print WRITER "Your message here, call 555-8467, extension $$!"; close WRITER; waitpid($pid, 0); # let the kid die } else { # if $pid is empty, this must be the child close WRITER; # so the parent can use it my $line = <READER>; print "What does this mean?\n\t>>$line<<\n"; close READER; # don't have to be explicit exit; }
I don't know how well it will work passing variables instead of explicit filehandle names to the pipe call. You might have better results with:
local *$read; local *$write;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: why?
by Anonymous Monk on May 05, 2000 at 07:34 UTC | |
by chromatic (Archbishop) on May 05, 2000 at 19:24 UTC |