Same treatment as I mentioned above: add Timeout, which is always good to have.

use POSIX; use strict; $|++; my $server = IO::Socket::INET->new( Type => SOCK_STREAM, Proto => 'TCP', LocalPort => 2500, Reuse => 1, Listen => 10, Timeout=>1 ); my $max_children = 3; my $current_children; my %children; sub interrupt { $SIG{CHLD} = 'IGNORE'; for( keys %children ) { kill KILL => $_ } exit; } sub chld { $SIG{CHLD} = \&chld; my $pid = wait; $current_children--; delete $children{ $pid }; print "Called\n"; } print "before preforking\n"; for( 0 .. $max_children ) { print "forking\n"; make_child(); print "after forking\n"; } print "----AFTER PRE-FORKING---------\n"; $SIG{CHLD} = \&chld; $SIG{INT} = \&interrupt unless $^O =~ /Win32/i; interrupt(); exit; while( 0 ) { sleep; my $i = $current_children; while( $i++ < $max_children ) { make_child(); } } sub make_child { my $pid; my $sigset; die "Error forking: $!" unless defined( $pid = fork ); print "After fork: $pid\n"; if( $pid ) { $children{ $pid }++; $current_children++; print "if(\$pid); returning\n"; return; } else { print "Else\n"; $SIG{INT} = 'DEFAULT'; while( 1 ) { #comment out these lines to prevent freezeing my $client = $server->accept() or last; handle( $client ); $client->shutdown(2); #here } print "exiting else\n"; exit; } print "never reached\n"; } sub handle { my $client = shift; my %headers; while( <$client> ) { s/\r\n$//; my( $k, $v ) = split/:/,$_,2; $headers{ $k } = $v; last if( length $_ == 0 ); } print "After headers\n"; print $client "HTTP/1.1 200 OK\nContent-Type: text/plain\n\nhi"; $client->shutdown(2); }

In reply to Re: Win32 fork and IO::Socket::INET->accept calls by pg
in thread Win32 fork and IO::Socket::INET->accept calls by BUU

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, details, 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, summary, 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.