A cheap hack, but will depend on how your OS operates:
if (-d "/proc/$pid") { ... }
This will likely work with most UNIX variants. As a bonus,
you can examine the command line parameters of that process
to see if it's the one you were expecting. On Linux, at least,
this is available in a pseudo-file:
sub GetProcessCommand
{
my ($pid) = @_;
return (open (PID, "/proc/$pid/cmdline") && <PID>);
}
This way you can validate the "authenticity" of the process
1:
# Check for buddy named 'xyz-proc'
if (GetProcessCommand($pid) =~ /xyz\-proc/) { ... }
Sometimes you will find a process active in that slot,
but for some reason it isn't yours.
1. This "authentication" is pretty loose, so be sure to check
the owner of the process too. You can masquerade your process
as anything you like by setting $0, after all, but you can't
change the uid of the process so easily.
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.