while (1) {
print "Enter a number: ";
$Number = <STDIN>;
chomp($Number);
print "You entered - $Number.\n";
}
yet you would have me believe it is.
When I said daemon, I meant having true daemon characteristics, not kinda sorta daemon-like.
Fork and exit, setsid, chdir /, close or redirect STDIN, STDOUT, STDERR.
Here's the example from Matt Sergeants' talk:
Daemonizing POE
- We often write daemons with POE (network daemons, cron daemons, etc
- But POE doesn't "background" automatically, so we need to write that:
use POE;
use POSIX;
$|++;
sub become_daemon {
my $child = fork;
die "Can't fork: $!" unless defined($child);
exit(0) if $child; # parent dies;
POSIX::setsid(); # become session leader
open(STDIN,"</dev/null");
open(STDOUT,">/dev/null");
open(STDERR, '>&STDOUT');
umask(0); # forget file mode creation mask
$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
}
become_daemon(); # MUST do this before we create any sessions
POE::Session->create(
inline_states => {
_start => sub { $_[KERNEL]->yield("loop") },
loop => sub { $_[KERNEL]->delay_set("loop", 10) },
});
$poe_kernel->run();
exit(0);
This example fails in the same way:
POE::Kernel's run() method was never called. |