#!/usr/bin/perl use strict; use warnings; use IO::Socket; use IO::Pipe; $SIG{CHLD}='IGNORE'; my $pipe = IO::Pipe->new(); die("Can't cerate Pipe") unless($pipe); my $sock = IO::Socket::INET->new( LocalHost => 'localhost', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $srun; while($srun = $sock->accept()) { my $pid1=fork(); my $pid2; if(defined($pid1)) { unless($pid1) { $pipe->reader(); run($pipe,$srun); } $pid2=fork() if($pid1); if(defined($pid2)) { $pipe->writer(); run($srun,$pipe); } else { kill(15,$pid1) if($pid1); } } $srun->close; } sub run { my ($sin,$sout)=@_; close(STDIN); close(STDOUT); close(STDERR); $sout->autoflush(1); $sin->blocking(0); my $buffer,$size; while($sin->opened() and $sout->opened()) { $sout->syswrite($buf,$size) while($size=$sin->sysread($buffer,1024)); select(undef,undef,undef, .05); } $sin->close(); $sout->close(); exit(); }