#!/usr/bin/env perl use warnings; use strict; use IO::Handle; # Setup a pipe (pipes are unidirectional) # Make sure to turn on autoflush on the writer, otherwise we may wait # a long, long time for data to come in. my ($from_client, $to_print_server); pipe $from_client, $to_print_server or die; $to_print_server->autoflush(1); # Fork off into our server and client if(fork()){ server(); } else { client(); } exit 0; # This is our server. We read from $from_client and print it. sub server { print "Info: Print service ready.\n"; while(<$from_client>){ print; } } # This is our client. We write to $to_print_server a incrementing integer # every now and then. sub client { my $i = 0; while(1){ print $to_print_server "i = $i\n"; $i++; sleep(int(rand(5))); } }