Thanx. I finally got it working with the following code.
use POSIX qw(:sys_wait_h); use IO::Socket; use DBI; $port=7272; $pid = fork; exit if $pid; die "Couldn't fork: $!" unless defined($pid); POSIX::setsid() or die "Can't start a new session: $!"; $time_to_die=0; sub signal_handler{ $time_to_die=1; } sub REAPER{ 1 until (-1 == waitpid(-1, WNOHANG)); } $SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler; $SIG{CHLD} = \&REAPER; $file="syncd.log"; open(LOG, ">>$file"); print LOG "Program Started : ".localtime()."\n"; until ($time_to_die){ ### Debug statement (uncomment to debug to log file) #print LOG "Until Loop\n"; $sock = IO::Socket::INET->new(LocalPort => $port, Type => SOCK_STREAM, Reuse => 1, Listen => 25, Timeout => 120) or die "Couldn't be +a tcp server on port $port : $@\n"; while($new_sock = $sock->accept()) { ### Debug statements (uncomment to debug to log file) #print LOG "While Loop\n"; #print LOG "Inside While new_sock Status: ".$new_sock."\n"; next if $child = fork; die "child fork: $!" unless defined $child; $sock->close; login($new_sock); exit 0; } close($sock); ### Debug statement (uncomment to debug to log file) #print LOG "Outside While new_sock Status: ".$new_sock."\n"; if($new_sock!=$sock->accept()){ report_crash(); respawn_syncd(); print LOG "Socket is Undefined Program Crashed to prevent infi +nite loop!\n"; $time_to_die=1; } } close(LOG);
Again thanx for the help. If you think I should have done it some other way let me know and I re-evaluate my code. I would hate to have a badly coded program because they only cause headaches later.

In reply to Re: Re: Re: Re: Daemonization of IO::Socket Script by landonc
in thread Daemonization of IO::Socket Script by landonc

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.