All,

I'm writing a server script that should stay running, for each client connection I fork a new child, but when I add "exit 0" at the end of the child code, the server script exist (even though the script doing the right thing). So, what I've read in that in Solaris 7 (and I'm assuming 8, since that is what I'm using) is that accept() does not automatically restart (after a child exits). If I take the "exit 0" everything looks fine, but it's leaving behind stray processes (not a good thing). Any help would be greatly apprieciated. Here is the code:
use strict; use warnings; use IO::Socket; use POSIX qw(:sys_wait_h); # use diagnostics; my $local = "172.23.167.114"; my $port = "7070"; my $maxconn = SOMAXCONN; my ($new_sock, $c_addr, $buf, $pid, $status); $|++; # NOTE: use netstat to see network properties. # ignore child processes to prevent zombies # $SIG{CHLD} = 'IGNORE'; # Using this actually makes all return codes + = -1 !! # $SIG{PIPE} = 'IGNORE'; sub REAPER{ my $pid = wait; # while ( waitpid(-1,WNOHANG) > 0 ) { } $status = $? >> 8; $SIG{CHLD} = \&REAPER; # wait for next child process } $SIG{CHLD} = \&REAPER; # wait for 1st child process my $sock = new IO::Socket::INET ( LocalHost => $local, LocalPort => $port, Proto => 'tcp', Listen => $maxconn, Reuse => '1', ); die "Could not create socket: $@ \n" unless $sock; print "RECEIVER::IP = $local PORT = $port MaxConn = $maxconn\n"; while (($new_sock, $c_addr) = $sock->accept() ) { die "Can't fork: $!" unless defined ($pid = fork()); if ( $pid == 0 ) { # Child code my ($client_port, $c_ip) = sockaddr_in($c_addr); my $client_ipnum = inet_ntoa($c_ip); my $client_host = gethostbyaddr($c_ip, AF_INET); print "CHILD CODE [cpid::$$]: Connection from: $client_host [$cl +ient_ipnum ", $new_sock->peerport, "] \n\n"; while (defined($buf = <$new_sock>) ) { if ($buf =~ /^EXECUTE:(.*)/ ) { print $1, "\n"; system("/msg/spgear/tools/bin/perl $1") || die "Could not +run program: $1 -- $!\n"; if ( defined $status ) { print $new_sock "RETURN CODE: $status \n"; undef $status; } else { print $new_sock "RETURN CODE: undef \n"; } } else { print "INVALID SYNTAX\n"; print $new_sock "INVALID SYNTAX\n"; } } # exit(0); } else { # Parent code $new_sock->close; print "\nPARENT CODE [ppid::$$ cpid:$pid]\n"; } }

In reply to In Solaris accept() is not restarted [on Solaris] ... by TASdvlper

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.