http://www.perlmonks.org?node_id=276411

djbiv has asked for the wisdom of the Perl Monks concerning the following question:

I have a server application written to accept data on a socket and spawn a child process using fork(); This applications is meant to accept online traffice to write data to a file for other applications use. I am wondering if there are any known limitations or issues with this type of processing? for example if the 'client' application is sending x amount of data to my listening port are there limitations to the number of child processess that can be kicked off? any comments or insight would be very helpfull!
This is the snippet of code that is handling the incoming connections and parent / child processing.
###################################################################### +########################## # M A I N ###################################################################### +########################## # Wait for a connect from the remote client my $acceptSock; my ($pid, $buf, $bufhdr, $req); while (1) { printf ("%sListening on port $args{p}\n", prHdr()); if (!($acceptSock = $listenSock->accept())) { print "bkpt 1: Accept failed: $!\n" if ($args{d} > 2); next; } # Spawn off a child to handle this connection my $pid = fork(); die "Cannot fork: $!" unless defined($pid); # PID is zero when we're the child if($pid) { print "Parent continues\n" if ($args{d} > 2); next; } printf ("%sAccepted connection from: %s\n", prHdr(), $acceptSock->p +eerhost()); srand(time); # Wait indefinitely for a message while (1) { open (FH, ">>$file"); print "Error reading 2-byte header: $!\n", last if (sysread($acceptSock, $bufhdr, 2) != 2); printf ("%sReceiving request\n", prHdr()); # We got the 2-byte (data length) header my $length = unpack("n", $bufhdr); print "$$: Length from request header = $length\n" if($args{d} > 2); print "Error length ($length) is < e-Header size ($EHDR_SIZE)\n", +last if ($length < $EHDR_SIZE); print "Error reading $length bytes of data: $!\n", last if (sysread($acceptSock, $buf, $length-2) != $length-2); my $msg = join('', $bufhdr, $buf); if($args{d} > 1) { # Got the data, display it &hexDump($bufhdr . $buf); # Got the data, display it &hexDump($bufhdr . $buf); print "\n"; } # Parse the message, creating hashes for the e-Header and ISO mess +age my ($hdr, $req) = &parse8583($bufhdr . $buf); # Dump the e-Header in readable form &printEHdr($hdr,1); if($args{d} && length($req)) { # Dump the individual ISO fields in the request print "ISO Request fields:\n"; for (sort numerically keys %$req) { if ($_ eq "48") { print " $_ =>\n"; &printDE48($req->{$_}); } elsif($_ eq "52") { my ($p1) = unpack("H16", $req->{52}); printf (" $_ => 0x%s\n",$p1); } # ADD processing of DE 127 if ($_ eq "127") { print " $_ =>\n"; &parse127($req->{$_}); } else { print " $_ => '", $req->{$_}, "'\n"; } } print "\n"; } printf("%sSending response\n", prHdr()); syswrite($acceptSock, $msg, length($msg)); close (FH); } printf ("%sChild done, closing socket\n", prHdr()); # Remote connection closed or error occured shutdown($acceptSock, 2); close($acceptSock); exit(0); } # Shouldn't be able to break out of the while(1) close($listenSock); die "Unexpected main loop termination";