Hello all!!!

I have perl-script, which pass filetail (like tail -f) through a socket on host:port via telnet . If connection keeps continuously all works normally. However at constant connection and switching-off the number of descendants decreases. What do I do not so?

#!/usr/bin/perl -w use File::Tail; use IO::Socket; use Symbol; use POSIX; $l = '/home/vilfred/socket/socket_demo.log'; $PORT=1234; # make server $server = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Type => SOCK_STREAM, Reuse => 1) or die " making socket: $@"; #make prefork child $PREFORK =5; $MAX_CLIENTS_PER_CHILD = 5; %children=(); $children=0; make_new_child() for(1 .. $PREFORK); $SIG{CHLD}=\&REAPER; $SIG{INT}=\&HUNTSMAN; while(1){ sleep; for($i=$children; $i<$PREFORK; $i++){make_new_child()} } sub tail_socket{ return $fi = File::Tail->new( name => $l, maxinterval => 0.1, adjustafter => 1000000000, interval => 4, tail => 0) } sub make_new_child{ my $pid; my $sigset; $sigset=POSIX::SigSet->new(SIGINT); sigprocmask(SIG_BLOCK, $sigset) or die "can't block SIGINT for fork: + $!\n"; die "fork: $!" unless defined($pid = fork); if($pid){ sigprocmask(SIG_UNBLOCK, $sigset) or die "can't unblock SIGINT for + fork: $!\n"; $children{$pid}=1; $children++; return; } else { $SIG{INT} = 'DEFAULT'; $SIG{CHLD}='IGNORE'; sigprocmask(SIG_UNBLOCK, $sigset) or die "can't unblock SIGINT for + fork: $!\n"; for($i=0; $i<$MAX_CLIENTS_PER_CHILD; $i++){ $client = $server->accept() or last; &tail_socket(); while(1){ do { #send data for client print $client $_; } while ($_=$fi->read); } } exit; } } sub HUNTSMAN{ local($SIG{CHLD})='IGNORE'; kill 'INT' => keys %children; exit; } sub REAPER{ $SIG{CHLD}=\&REAPER; my $pid = wait; $children--; delete $children{$pid}; }
Thank you!

In reply to prefork servers with reconnect dont work by vilfred

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.