LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   BASH: Waiting for a process to end, problem with wait (https://www.linuxquestions.org/questions/linux-general-1/bash-waiting-for-a-process-to-end-problem-with-wait-796539/)

patolfo 03-19-2010 12:06 PM

BASH: Waiting for a process to end, problem with wait
 
Hi there folks, i came along with yet another issue with the wait command in BASH

The thing is i used BASH to run another script which is not mine, several times in a for loop. But i need to open the log files after each time the script that modifies some text file is done. I tried with wait and using the PID, but it says something like the process is not spawned from that console/terminal, so i recurred to a more dumb approach:

Code:

#        Wait till current file is gone
function espera
{
sleep 3
current= path/$1.$2.string.current; # This is the temp file, deleted after the main script finishes
while [ -e $current ]
do
let i=1 # Dumb operation to keep the while loop running
done
sleep 1
busca $1 $2
prometeo $1 $2
}

busca() is for looking the actual log file and opening it; whilst prometeo(), logs the new data into a database

neonsignal 03-19-2010 07:26 PM

If you are going to use a busy loop to wait for a non-child process, at least put a delay time in the loop, otherwise you will be wasting CPU cycles (and electricity). For example, the following bash code will busy-wait for a process to finish:
Code:

while [ -e /proc/$PID ]; do sleep 0.1; done

catkin 03-19-2010 11:54 PM

If you want a dummy command, : is provide for exactly that purpose
Code:

c@CW8:~$ help :
:: :
    No effect; the command does nothing.  A zero exit code is returned.



All times are GMT -5. The time now is 10:19 PM.