yucca15 has asked for the wisdom of the Perl Monks concerning the following question:
I know I am probably missing something very obvious, but this initiate hasn't got a scooby. Thanks in advance!#!/usr/local/bin/perl -w use Proc::Daemon; use strict; my $root = "/temp"; my $time_to_die = 0; sub signal_handler { $time_to_die = 1; } sub phoenix { my $me = "$root/minidaemon.pl"; logMessage("I'm about to refork by running '$me'!"); my $ret = system($me); if ($ret) { logMessage("Should have run system($me), but which returned $r +et: $?, carrying on"); } else { exit(0); } } sub logMessage { my $message = shift; local $| = 1; open(FILE_HANDLE, ">>$root/daemon.out") or die("log file open fail +ed: $!"); print FILE_HANDLE "$$ : $message\n" ; close(FILE_HANDLE); } Proc::Daemon::Init; $SIG{INT} = $SIG{TERM} = \&signal_handler; $SIG{HUP} = \&phoenix; while (!$time_to_die) { sleep(1); logMessage("hello"); } logMessage("died");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Restarting a daemon
by chromatic (Archbishop) on Jan 22, 2004 at 18:57 UTC | |
|
Re: Restarting a daemon
by Abigail-II (Bishop) on Jan 22, 2004 at 19:29 UTC | |
|
Re: Restarting a daemon
by revdiablo (Prior) on Jan 22, 2004 at 19:06 UTC |