landonc has asked for the wisdom of the Perl Monks concerning the following question:
use POSIX qw(:sys_wait_h); use IO::Socket; use DBI; $port=8080; $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)); } $sock = IO::Socket::INET->new(LocalPort => $port, Type => SOCK_STREAM, Reuse => 1, Listen => 25, Timeout => 120) or die "Couldn't be a tc +p server on port $port : $@\n"; $SIG{INT} = $SIG{TERM} = $SIG{HUP} = \&signal_handler; $SIG{CHLD} = \&REAPER; until ($time_to_die){ while($new_sock = $sock->accept()) { next if $child = fork; die "child fork: $!" unless defined $child; $sock->close; login($new_sock); exit; } close($sock); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Daemonization of IO::Socket Script
by skyknight (Hermit) on Aug 08, 2003 at 18:21 UTC | |
by landonc (Novice) on Aug 08, 2003 at 18:31 UTC | |
by landonc (Novice) on Aug 08, 2003 at 18:33 UTC | |
by landonc (Novice) on Aug 08, 2003 at 18:46 UTC | |
by skyknight (Hermit) on Aug 08, 2003 at 19:42 UTC | |
by landonc (Novice) on Aug 08, 2003 at 20:27 UTC | |
|
Re: Daemonization of IO::Socket Script
by bobn (Chaplain) on Aug 08, 2003 at 21:07 UTC |