LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-19-2010, 12:06 PM   #1
patolfo
Member
 
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:

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

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

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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
 
Old 03-19-2010, 11:54 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
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.
 
  


Reply


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 linuxquestions.org...' ..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


All times are GMT -5. The time now is 05:07 PM.

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