# server.pl use strict; use warnings; use POSIX (); my $cgis = 0; $SIG{CHLD} = sub { while ( waitpid( -1, POSIX::WNOHANG ) > 0 ) { $cgis -= 1; } }; while (1) { print '(Ctrl-D to quit)> '; my $request = ; last if not defined $request; chomp $request; print "Server: about to fork a CGI client\n"; $ENV{foo} = 'bar'; # use some real $ENV{baz} = 'quux'; # CGI variables pipe my ( $child_stdin, $input_to_child, ); pipe my ( $output_from_child, $child_stdout, ); my $pid = fork; if ( $pid == 0 ) { close $input_to_child; close $output_from_child; open STDIN, '<&', $child_stdin; open STDOUT, '>&', $child_stdout; exec {'perl'} 'perl', 'client.pl'; } else { close $child_stdin; close $child_stdout; print "Server: forked process $pid\n"; $cgis += 1; print $input_to_child $request; close $input_to_child; print "Server: reading child response\n", <$output_from_child>; } } print "Server exiting, remaining children: $cgis\n"; #### # client.pl use strict; use warnings; my $input = ; print <