Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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";

In reply to fork processing limitations by djbiv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (7)
    As of 2018-07-16 20:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (349 votes). Check out past polls.

      Notices?