I would go further than checking the content of /var/run/syslogd.pid and seeing whether there's a process running with that id. After all, if syslogd went down, another process could have taken PID syslogd was using.
Furthermore, to check whether a PID is in use, and what program is using it, I would use neither kill, nor ps. I'd run something like (untested):
my $pidfile = "/var/run/syslogd.pid";
if (-e $pidfile &&
qx "cat /proc/`cat $pidfile`/cmdline" =~ /^syslogd$/) {
... syslog is running ...
}
Notes:
- On my systems, you must be root to be able to read /var/run/syslogd.pid. Your milage may vary.
- It's not foolproof. Something may have removed the PID file for instance.
- This is for a 2.4 Linux kernel. Different OSses (or Linux versions) may have a different /proc file system layout, or no /proc filesystem at all. The information from the file cmdline may be elsewhere, or not available at all.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.