wait in shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wait in shell scripts
# 1  
Old 09-23-2004
wait in shell scripts

Hi

I am creating 3 background processes in my shell script using &.
I have obtained the 3 PIDs of the background processes using $!.
I need to wait for these to complete and i need the exit status of each of these.

If i use :
wait $PID1
wait $PID2
wait $PID3

and get the exit status of each of these waits using $?, then by the time i call wait for, say PID3 , it may have already terminated !!

Whereas if i use :
wait $PID1 $PID2 $PID3
then i only get the exit status of PID3

If i use wait without specifying any operands then it exits with status 0 after all the processes have terminated even if one of the processes fails.

I need to know if any of the procs fails. How do I do this in my shell script......can i use waitpid in my shell script and how?

Thanks in advance!
# 2  
Old 09-23-2004
wait does not have that much power in shells. About the only way would be to launch a separate subshell for each background process. Then each subshell would launch a background process, wait for it, and report the return code in a data file. The main script would be waiting for the files to exist.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Help with shell Script ,wait for some files for some time??

Hi All, I have the requirement that ,i have to write a shell script that job has to wait for a 7 touch files created by another application for 4 hours, if i get all 7 touch files ,i have to send a mail that i jobs are completed, if if it is waiting for more than 4 hours i have to send a mail... (2 Replies)
Discussion started by: Pradeep Shetty
2 Replies

2. Shell Programming and Scripting

Wait for one processes to complete in a shell script

Let's say I start process A.sh, then start process B.sh. I call both of them in my C.sh How can I make sure that B starts its execution only after A.sh finishes. I have to do this in loop.Execution time of A.sh may vary everytime. It is a parameterized script. (17 Replies)
Discussion started by: rafa_fed2
17 Replies

3. Shell Programming and Scripting

Korn shell. wait command and crontab

I have the following ksh script: sqlplus usr1/pw1@DB1 @$DIR/a.sql $1 & sqlplus usr2/pw2@DB2 @$DIR/b.sql $1 & wait echo "Done!" Where $DIR is a variable with the absolute path where a.sql and b.sql are. For some time, I've been running this script daily and it works fine. The intentions is... (5 Replies)
Discussion started by: acarpio89
5 Replies

4. Shell Programming and Scripting

calling a shell script in background and wait using "wait" in while loop

Hi, I am facing a strange issue, when i call a script from my while loop in background it doesnt go in background, despite the wait i put below the whil loop it goes forward even before the process put in background is completed. cat abc.txt | while read -u4 line do #if line contains #... (2 Replies)
Discussion started by: mihirvora16
2 Replies

5. Shell Programming and Scripting

Shell script runs fine in Solaris, in Linux hangs at wait command

HI, I have a strange problem. A shell script that runs fine on solaris. when i ported to linux, it started hanging. here is the core of the script CFG_FILE=tab25.cfg sort -t "!" -k 2 ${CFG_FILE} | egrep -v "^#|^$" | while IFS="!" read a b c do #echo "jobs output" #jobs #echo "jobs... (13 Replies)
Discussion started by: aksaravanan
13 Replies

6. UNIX for Dummies Questions & Answers

Wait Process in Shell Scripting.

Hello, I have a script that needs to wait till the previous process is done within the same script.But my script doesnt wait till that it is done.Can anyone suggest how I can stop my process till the previous task is done. I tried 'wait' but I dont have a static process id so is there... (2 Replies)
Discussion started by: sud
2 Replies

7. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

8. Shell Programming and Scripting

wait for 5 seconds in shell script

hi how can i wait for 5 seconds inside my shell script? 'wait 5' command doesnot seem to be working? (2 Replies)
Discussion started by: gopsman
2 Replies

9. Shell Programming and Scripting

Need to execute 2 scripts, wait, execute 2 more wait, till end of file

:cool: I need to execute a shell script to do the following: cat a file run two back ground processes using the first two values from the file wait till those background processes finish run two more background processes using the next two values from the file wait till those background... (1 Reply)
Discussion started by: halo98
1 Replies

10. UNIX for Advanced & Expert Users

How can I wait for PID to finish in another shell

Have a need to schedule programs that can run after other programs are completed. Here's the catch: 1) The list of programs will not always be the same (kind of a plug-n-play deal) 2) The invoking shell may not be the same as the shell of the program being waited on In other words, I need... (2 Replies)
Discussion started by: superdelic
2 Replies
Login or Register to Ask a Question