Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 03-19-2010, 12:06 PM   #1
Registered: Jan 2006
Distribution: Debian-Sarge r2-k.2.6.8-2.386
Posts: 101
Blog Entries: 1

Rep: Reputation: 15
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:

#	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 ]
let i=1 # Dumb operation to keep the while loop running
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

Last edited by patolfo; 03-19-2010 at 12:07 PM.
Old 03-19-2010, 07:26 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
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:
while [ -e /proc/$PID ]; do sleep 0.1; done
Old 03-19-2010, 11:54 PM   #3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If you want a dummy command, : is provide for exactly that purpose
c@CW8:~$ help :
:: :
     No effect; the command does nothing.  A zero exit code is returned.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Bash] Waiting for a process to terminate or stopping it after some time hamtavs Linux - General 2 12-12-2008 05:25 PM
How to wait for the process and know if the exit code of the sub process williamhomanchun Linux - General 10 08-11-2008 01:32 PM
kill a waiting process using shellscript ranmahs Linux - General 5 12-07-2007 03:56 AM
My browser, all day today: 'waiting for' ..waiting.. waiting .. GrapefruiTgirl LQ Suggestions & Feedback 18 05-25-2007 05:35 AM
Bash problem: detecting end of stream tvynr Linux - Software 2 11-08-2006 10:12 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration