The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
wait for 5 seconds in shell script gopsman Shell Programming and Scripting 2 08-30-2007 05:47 AM
Need to execute 2 scripts, wait, execute 2 more wait, till end of file halo98 Shell Programming and Scripting 1 08-01-2006 04:42 PM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-12-2006 02:27 AM
How can I wait for PID to finish in another shell superdelic UNIX for Advanced & Expert Users 2 01-17-2005 10:17 PM
where to put shell scripts? ober5861 UNIX for Dummies Questions & Answers 7 07-17-2001 09:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-23-2004
Vinaya Vinaya is offline
Registered User
  
 

Join Date: Sep 2004
Posts: 1
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 (permalink)  
Old 09-23-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0