I'm kinda curious why all the work?

perl -e 'system(@ARGS) while 1' your program with args here
The system function is merely a glorified wrapper around fork and exec anyway, complete with a wait. If you want it to daemonise and ignore signals, just add a few characters:
nohup perl -e 'system(@ARGS) while 1' your program with args here &
Ok, that's not quite the same as daemonising, but it's often close enough for most purposes.

Now, if the program you're trying to monitor goes and daemonises itself, well, then you have a completely different problem which I don't think anyone has addressed. In that scenario, you probably want to use pgrep (which solves the "grep finding itself" problem for you) in a similar structure to what you have. However, don't use backticks when system will do. Just a bad idea.


In reply to Re: running program? by Tanktalus
in thread running program? by rsiedl

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.