Driver script kicks off supporter scripts in background.
The supporter script writes it's own PID ($$) into a status file. When script completes, deletes the PID from the status file.
Quote:
echo $PID >> $STATUS
##blah...blah
sed '/'$PID'/d' $STATUS > $STATUS.$$
mv $STATUS.$$ $STATUS
The driver script constantly polls this status file for number of lines. As and when it's get lower than XX number of lines, fires off another supporter script in background. This continues till all supporter scripts have started and then the driver program just waits for the $Status file line count to go to zero and stops.
Problem:
+++++++++++
I am echoing putting the $PID into Status file and removal too. I am seeing both in nohup.out. However, VERY, VERY ERRATICALLY sometimes although the echo statements on removal success are present, the $STATUS file still shows the PID! I checked and also determined these PIDs are indeed unique. Why is it that although the sed command runs successfully (the echo on removal is after the sed command with a if .. $? -eq 0 clause) the actual delete do not happen? Is it because at that point in time 2 or more background processes are "attacking" the $STATUS file and somehow sed fails to recognize it? What can be done to ensure that the sed command really does delete the entry, i.e. obtain a file lock/handle, etc. I think it's obvious, but the STATUS file is common.