Detecting when a process has finished (but not exited)

Posted by Egwor on Stack Overflow See other posts from Stack Overflow or by Egwor
Published on 2010-04-22T07:40:06Z Indexed on 2010/04/22 7:43 UTC
Read the original article Hit count: 156

Filed under:
|
|

I have a program that's run in unix (that I have no control over) that when finished prints 'Completed successfully' but does not exit. I want to automatically detect when the process finishes (by checking the output of the command), so that I can kill the process and so that I can proceed do other activities. The complexity comes because I want to be able to run multiples of these scripts concurrently. (One activity I need to do requires the script to be called with various inputs, but each time the script runs it takes a while to return, and so I want to do them in parallel)

Has anyone done something similar to this? I could redirect the stderr and stdout output of the command to a temporary file which has a random file name, then tail the file and pipe to grep for the end conditions (I.e. the certain log lines). The problem is, surely tail -f would keep running, and so it would never exit. Should I poll? If so, what's the best approach?

© Stack Overflow or respective owner

Related posts about bash

Related posts about polling