At 02:57 AM 5/1/2002 -0400, Peter Chen wrote:
>What is the convention for handling daemonization in a POE application?
I am unsure how kosher this solution is, but it's "functional" as far as I
know. I jacked the daemonize() routine out of perlfaq and called it just
before $poe_kernel->run(); See below.
-a
daemonize();
$poe_kernel->run();
exit 0;
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: $!";
}