Hi Guys,

i have the following......
file.pl
#!/usr/bin/perl use warnings; use strict; #!/usr/bin/perl use warnings; use strict; use IO::Socket; $| = 1; my $port = 7777; my $server = IO::Socket ->new( Domain => PF_INET, LocalPort => $port, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1, ); die "Bind failed: $!\n" unless $server; #tell OS to clean up dead children $SIG{CHILD} = 'IGNORE'; print "Multiplex server running on port $port...\n"; while(my $connection = $server->accept){ my $name = $connection->peerhost; my $port = $connection->peerport; if (my $pid = fork){ close $connection; next; # on to the next connection }else{ # child process - handle connection print $connection "You're connected to the server!\n"; while (<$connection>){ use HTTP::Date; my ($date, $time) = split(" ", HTTP::Date::time2iso()); my ($hour, $min) = split(":", $time); my $log; open ($log, '+>>',"logs/$port $date.txt") || die "Couldn't op +en log.txt: $!"; print $log $_; close $log; my $dir = "logs"; my $file = "logs/$port $date.txt"; chmod (0777, $file); chmod (0777, $dir); } $connection->shutdown(SHUT_RDWR); } }
Basically all it does is listen for conections on a certain port number, and then writes the data recieved to a log file,
the above code works 100% for what i need,
My problem is if i start the script using Putty SSH like so ./file.pl
then its all fine, it creates the connections and if the connection is terninated it cleans up the dead children from the server, and releases the port again,
however, if i start the script like so
nohup ./file.pl
then it doesnt cleen up the dead children and keeps the port also in use after the host has disconnected
I need this file to be running all the time, could someone please tell me the correct way of doing this, or is there a problem in my script somewhere?

Please guys i really need to try and get this fixed

K-

In reply to How Can I Reliably Cleanup Sockets in a Backgrounded Program? by xarex

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.