Har.

A program I am working on uses a control panel setup for operation. Everything is done with buttons in a form. When the main portion of the program is executed, it forks off and operates in the background. You can monitor its progress by viewing a log file it creates as it goes.

Now, the background process can take anywhere from a handful of seconds to quite a few minutes to complete. I want add a way for users to kill the background process if they need to. Currently, I have the process write it's PID to a file (which doubles as a lock to prevent multiple instances of the program from being run at the same time). So, when a user wants to stop the process, the control panel portion of the script can get the PID out of the file and kill it. The problem is, I want to be able to get the process name of PID xxx so I can have the script check and be sure that pid xxx is what it should be. I don't want to have someone click the "kill" button a week after the script has stopped and kill some other process that just happens to share the same number (of course, the script deletes the lock/PID file when it finishes so this shouldn't happen, but just in case...). I want to do this using PERL functions, if possible. I don't want to make system calls to ps or anything like that if I can avoid it, but that's what my searches keep turning up.

I know that there are a lot of factors conspiring against me accidentally killing off the wrong process, but I suffer from paranoia. I don't like to leave anything to chance. I'd appreciate it if someone can point me in the right direction.

Thanks,
SpaceAce


In reply to Killing wayward children by SpaceAce

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.