There are certain things you need to do with a daemon, to make it a real daemon. Search groups.google.com for "perl daemon" for alot of discussion and sample scripts. There is also a modules to make it easy....
Proc::Daemon
Here is the basic idea.
#!/usr/bin/perl
use warnings;
use strict;
use POSIX 'setsid';
use IO::Socket;
$|++;
my $server = new IO::Socket::INET (
LocalHost => 'localhost',
LocalPort => '7070',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $server;
$server->autoflush(1);
daemonize();
open(LOG,">/tmp/7070.log") or die "$\n";
while(1){
while ( my $client = $server->accept() ){
sysread($client, my $buf, 100);
syswrite(LOG, "$buf\n");
LOG->flush;
}
}
#################################################################
sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>/dev/null'
or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
}