I think you might get the best results using fork: the parent process spawns a child process (and has the child's pid); the child does an "exec ..." to run the external program in question. This makes sure that when the external program is running, it has the same pid as the child process that started it.

The parent could check the age of the file, or check the size (with the "-s" operator -- see the -X section of the perlfunc man page), sleeping for maybe 3 or 5 seconds between checks. If the file hasn't grown since the last check, kill the child pid and start a new child. Continue doing that as long as you want.

(Update: added link to docs for the "kill" function, to clarify that this is a built-in.)


In reply to Re: Keeping a program running by graff
in thread Keeping a program running by Anonymous Monk

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.