#!/usr/local/bin/perl -w use strict; # pipes.pl - demonstrate IPC with fork and pipe in Perl # Andrew Ho (andrew@tellme.com) pipe(READER, WRITER); { my $fh = select(WRITER); $| = 1; select($fh); } my $child_pid = fork(); if ($child_pid == 0) { close READER; print STDOUT "inside child, pid = $$\n"; print WRITER "(child pid $$ is sending this)\n"; close WRITER; exit; } else { close WRITER; print STDOUT "inside parent, pid = $$, child pid = $child_pid\n"; while() { print "reading from child: $_"; } close(READER); waitpid($child_pid, 0); } exit 0;