Thanks, everyone! First, you are correct that running from another script does work fine; to my embarrassment, in my test I used a relative path with FindBin and was looking in the wrong directory for the pid file. This solution works.

However, in the course of this, I picked through the Daemon::Control code, and I'm a bit underwhelmed. Well, useful is the (undocumented, but callable) pid_running method, which does the actual check, and is used by (e.g.) do_status. But this method's MO seems quite inadequate; its only test is to SIG0 the pid. This means that if your daemon crashed and a new process shows up using the same pid the daemon had, then, e.g., do_stop will blindly kill this process!

There is an optional scan_name parameter which does a bit more checking. It does this by spawning a UNIX shell which runs ps to see if the process matches a regex; this seems rather roundabout and inefficient, as opposed to (say) reading /proc/####/cmdline or lstat'ing /proc/####/exe. Maybe it's more portable?

In any case, it's unsettling that this extra test is not the default, so that running Daemon::Control in the usual way can be unsafe. I'd previously assumed it was much more robust than this. Beware.


In reply to Re^2: Test if Daemon::Control daemon is running. by gh
in thread Test if Daemon::Control daemon is running. by gh

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.