#!/usr/bin/perl -w # pipe2 - use pipe and fork so child can send to parent use IO::Handle; pipe(READER, WRITER); WRITER->autoflush(1); if ($pid{vmstat} = fork()){ print "Parent from vmstat\n"; close WRITER; while (){ chomp $_; print "Parent Pid $$ just read this: `$_'\n"; } } else { die "cannot fork: $!" unless defined $pid{vmstat}; close READER; open IN, "vmstat 5 5|"; while (){ chomp $_; print WRITER "Child Pid vmstat $$ is sending this --->$_<---\n"; } close WRITER; # this will happen anyway exit; } waitpid($pid{vmstat},0); close READER; pipe(READER, WRITER); WRITER->autoflush(1); if ($pid{iostat} = fork()){ print "Parent from iostat\n"; close WRITER; while (){ chomp $_; print "Parent Pid $$ just read this: `$_'\n"; } } else { die "cannot fork: $!" unless defined $pid{iostat}; close READER; open IN, "iostat 5 5|"; while (){ chomp $_; print WRITER "Child Pid iostat $$ is sending this --->$_<---\n"; } close WRITER; # this will happen anyway exit; } waitpid($pid{iostat},0); close READER;