use IO::Socket qw(:DEFAULT :crlf); use IO::File; use constant PIDFILE => "/tmp/prefork.pid"; use constant PREFORK_CHILDREN => 3; my $port = shift || 1426; my $socket = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Listen => 5, Reuse => SO_REUSEADDR, Type => SOCK_STREAM ) or die "Can't create listen socket: $!"; # create PID file, initialize logging, and go into background #init_server(PIDFILE); make_new_child() for (1..PREFORK_CHILDREN); exit 0; sub make_new_child { #my $child = launch_child(); my $child = fork; return if $child; do_child($socket); # child handles incoming connections exit 0; } sub do_child { my $socket = shift; while (1) { local $/ = "\n"; next unless my $c = $socket->accept; handle_connection($c); close $c; } close $socket; } sub handle_connection { my $x = shift; my $sz = <$x>; print $x "Testing\n"; }