Waiting for a background process to finish


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Waiting for a background process to finish
# 1  
Old 08-08-2008
Waiting for a background process to finish

Hello,
I am a novice shell script programmer. And facing this problem any help is appreciated.
I m writing a shell script and running few commands in it background as I have to run them simultaneously.
Sample code :

sql_prog &
sql_prog &
sql_prog &
echo "Process Completed"

Here sql_prog is user defined function which runs some sql queries.
The problem is as soon as it executes these last sql_prog it quickly prints the last statement. I want that the program should wait for last echo statement and print it only once all the above 3 sql_prog are finished.
Is there any easier way to do this.

Thanks
# 2  
Old 08-08-2008
One way

Code:
sql_prog &
sql_prog &
sql_prog &
wait
echo "Process Completed"

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 08-11-2008
Fantastic, It worked and above all a very simple way. Many thanks for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Waiting a job to finish

Hello again, I am runnning a job on a cluster and I submit a job with the command qsub script.sh where script.sh is a script with the command i want o use. When i enter this command the cluster gives a huber like 123456 as the JOB ID. I want the job to run about 12 hours and when it... (5 Replies)
Discussion started by: lengolass
5 Replies

2. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

3. Shell Programming and Scripting

waiting on jobs in bash, allowing limited parallel jobs at one time, and then for all to finish

Hello, I am running GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu). I have a specific question pertaining to waiting on jobs run in sub-shells, based on the max number of parallel processes I want to allow, and then wait... (1 Reply)
Discussion started by: srao
1 Replies

4. Shell Programming and Scripting

Waiting for the background process to finish

Hi, I have on shell script which internally calls more than one scripts which run in background. These scripts cannot be modified to run in foreground. eg. myscript.sh -> bulk_launcher.sh -> acq_launcher.sh -> bulk_loader.sh I want the calling shell script myscript.sh to wait till the... (7 Replies)
Discussion started by: AB10
7 Replies

5. UNIX for Dummies Questions & Answers

Cygwin not waiting for program in background (solved)

Hello, I know this isn't exactly a Unix question, but I wasn't able to find much information elsewhere. I'm trying to run a program in the background using Cygwin on a Windows machine, then use the wait command to pause before proceeding. Unfortunately, as I've confirmed using ps aux, the... (0 Replies)
Discussion started by: ocdcollector
0 Replies

6. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

7. Shell Programming and Scripting

Waiting for an arbitrary background process (limiting number of jobs running)

Hi, I'm trying to write a script to decompress a directory full of files. The decompression commands can run in the background, so that many can run at once. But I want to limit the number running at any one time, so that I don't overload the machine. Something like this: n=0 for i in *.gz... (15 Replies)
Discussion started by: p.f.moore
15 Replies

8. AIX

Waiting time of Process

Hi all, I am trying to find out the process wait time on Unix(AIX/SOLARIS) machine( only sh/ksh/csh): Like EXAMPLE 1 : $ vmstat 2 System configuration: lcpu=16 mem=32000MB kthr memory page faults cpu ----- -----------... (4 Replies)
Discussion started by: chandrakala.sg
4 Replies

9. UNIX for Advanced & Expert Users

Process(s) ID waiting on IO?

Hello Experts!! My CPU is waiting a lot (around 33%) on I/O. I would like to find out what process(s) are waiting on the i/o. Below is my real time output of vmstat and sar. Thanks for you help !!!! Regards Citrus OS: AIX - 5L : /u2/oracle >oslevel 5.3.0.0 : /u2/oracle... (9 Replies)
Discussion started by: Citrus143
9 Replies

10. Linux

waiting process

how to know the information of the waiting process how to calculate the time of the process that it has taken to execute i want to make a program that Should be able to keep a log of the processes expired(The log should contain the starting time, expiry time, time slices used, total execution... (2 Replies)
Discussion started by: shukla_chanchal
2 Replies
Login or Register to Ask a Question