Hello, I'm trying to write a daemon which will restart itself when it receives SIGHUP. Whenever I send the signal, the daemon never seems to start a new one using the system call (I get a return code of 512 - what does that mean?). I'm using the following code:
#!/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");
I know I am probably missing something very obvious, but this initiate hasn't got a scooby. Thanks in advance!

In reply to Restarting a daemon by yucca15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.