I have a (closed source, proprietary, external) program with a tendency to stop working (not die - just quit doing things, likely due to network latency).

I want to write a short perl program that checks to make sure the program hasn't stopped. Since it writes to a several times a second (when working), I thought I could check the time of the file every second (with "sleep 1"), and if it differed from the current time by more than a second, kill the program and restart it.

Does the idea sound reasonable or does someone know a completely different (better) approach? I assume I would use "exec" (and not "system") to start the program. Does some easy way exist to get the process number to kill it? Any other pitfalls to avoid?


In reply to 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.