in reply to Keeping a program running

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.)

Replies are listed 'Best First'.
Re^2: Keeping a program running
by Anonymous Monk on May 09, 2007 at 06:07 UTC
    That looks like it will work very well.

    One question, though - how do I test for the parent versus the child (so I know to start the external program in the child and not in the parent)?

      That's covered pretty well in the referenced man page for fork: it returns undef on failure, zero in the child process, and the child's pid in the parent process.