Sample Header Ad - 728x90

How to poll existence of a background script correctly

5 votes
3 answers
7833 views
I have a problem with the following kind of script: #!/bin/sh long_running_script.sh & while [ pidof long_running_script.sh ] do echo "." sleep 1 done The sript will start a new script to background, and it should print dots until the backgroud script will exit. It works when CPU load is not high. But, when there is high CPU load, it won't work: long_running_script.sh will start, but the 'parent' script will exit from while loop before the long_running_script.sh exits. Seems that pidof is executed before the long_running_script.sh is really started (execved). What is the best way to solve this problem? 1 seconds sleep before the while statement didn't help. So I don't want to use any magic delays, because it may be unreliable.
Asked by SKi (153 rep)
Sep 20, 2012, 10:50 AM
Last activity: Oct 25, 2014, 03:48 AM