#!/usr/bin/perl
use POSIX qw(setsid);
use strict;
sub go_fork_your_self {
print "I become daemon dude.\n";
my $pid;
defined($pid = fork) or die("ERROR: Can't fork my self: $!");
if ( $pid ) {
# Parent process
}else{
# Child process
setsid or die "ERROR: $!";
select(undef, undef, undef, 0.25);
&start_program();
}
}
sub start_program {
$0 = 'weby_daemon';
print "i'm a program with pid $$\n";
while (1) {
sleep 10;
print "Cya after 10 seconds dude.\n";
}
}
&go_fork_your_self();