Wait command help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Wait command help
# 1  
Old 09-24-2009
Wait command help

Hi, Is there any way to know the child process status as and when it finished. If i write like below
nohup sh a1.sh & ### has sleep 20 ;echo a1.sh
nohup sh a2.sh & ### has sleep 10 ;echo a2.sh
nohup sh a3.sh & ### has sleep 5 ;echo a3.sh
wait
This will wait till a1.sh ,a2.sh a3.sh completes. I want to know individual status immediately as it finishes. In the above a3.sh has sleep of 5 , this should come out and display a3.sh. I tried to use wait PID, this command is given one at a time
wait $pid1 ; echo $?
wait $pid2; echo $?
wait $pid3 ; echo $?
Please let me know how this should be done. I don't want wait till all child process finishes. I want it to display as and when it completes. Any help really appreciated.
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nohup and wait command usage

while read list do nohup ./process.sh $list & process_id=$! wait $process_id done < sample.lst command1.. command2.. //Am calling a shell script within and firing the multiple processes concurrently. (8 Replies)
Discussion started by: manid
8 Replies

2. Shell Programming and Scripting

Proper Use of WAIT Command Within .ksh

I am trying to write a korn shell script (Z.ksh) that will execute three other korn shell scripts within it. The three korn shell scripts (A.ksh,B.ksh,C.ksh) each execute a series of .sas programs. A.ksh, B.ksh, and C.ksh must each wait until the last .sas program within them executes and finishes... (2 Replies)
Discussion started by: imoore
2 Replies

3. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

4. UNIX for Dummies Questions & Answers

How do you wait for command substitution processes to complete?

When running a command using the >(cmd) syntax in bash how do you wait for the command to complete before moving on in your script? Here is a simple example: zcat largefile.gz | tee >(wc && echo “HELLO”) > /dev/null # I tried wait, here but it doesn't wait for the process in the subshell.... (8 Replies)
Discussion started by: mrvwman
8 Replies

5. Shell Programming and Scripting

wait command

Hi all, I have never used the wait command before and want to know how it works. I basically need to run four sqlplus sessions in parallel as background processes and i am spooling the results obtained from the database into files.I need to wait for all the processes to finish and then make... (2 Replies)
Discussion started by: vinoo128
2 Replies

6. Shell Programming and Scripting

Is there a way to ask expect wait for sometime before running the next send command ?

Hi all, After expect catches the string I specify, is there a way to ask expect wait for sometime before running the next send command ? So my script looks like following, expect "some string" #How to ask expect to wait for a while send "next command" The reason I want to do this is... (0 Replies)
Discussion started by: qiulang
0 Replies

7. Shell Programming and Scripting

help in wait or sleep command

Hi All, I have a script which runs 3 scripts. The first script creates two files. The other two scripts should run only when the files are created. I tried the following for loop , but it is not working. Can someone please help me. while ; do # Sleep until file does exists/is created... (4 Replies)
Discussion started by: nua7
4 Replies

8. 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

9. Shell Programming and Scripting

Wait Command

Does anyone have an example of a korn shell scripts kicking of multiple background processes and then using the wait command to get the return code from those processes? I want to write a program that kicks off multiple Oracle procedures and then wait for the return code before I procede.... (1 Reply)
Discussion started by: lesstjm
1 Replies

10. Shell Programming and Scripting

Help with wait command

I have a script that runs numerous other scripts. I am using a wait command to try and get the calling script to wait for all process called to finish before proceeding. Issues How can I set wait to timeout IE a called program never terminates. Alternatively how can I check the called... (1 Reply)
Discussion started by: ultraman
1 Replies
Login or Register to Ask a Question
wait(1) 						      General Commands Manual							   wait(1)

NAME
wait - Awaits process completion SYNOPSIS
wait [pid] Note The C shell has a built-in version of the wait command. If you are using the C shell, and want to guarantee that you are using the command described here, you must specify the full path /usr/bin/wait. See the csh(1) reference page for a description of the built-in command. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: wait: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
One of the following: The unsigned decimal integer process ID of a command, for which the utility is to wait for the termination. A job control job ID that identifies a background process group to be waited for. The job control job ID notation is applicable only for invoca- tions of wait in the current shell execution environment. The exit status of wait is determined by the last command in the pipeline. DESCRIPTION
When an asynchronous list is started by the shell, the process ID of the last command in each element of the asynchronous list becomes known in the current shell execution environment. If the wait utility is invoked with no operands, it waits until all process IDs known to the invoking shell have terminated and exits with a zero exit status. If one or more pid operands are specified that represent known process IDs, the wait utility waits until all of them have terminated. If one or more pid operands are specified that represent unknown process IDs, wait treats them as if they were known process IDs that exited with exit status 127. The exit status returned by the wait utility is the exit status of the process requested by the last pid operand. The known process IDs are applicable only for invocations of wait in the current shell execution environment. RESTRICTIONS
If wait is called in a subshell or separate utility execution environment, such as one of the following, it returns immediately because there are no known process IDs to wait for in those environments: (wait) nohup wait ... find . -exec wait ... ; If the exit status of wait is greater than 128, there is no way for the application to know if the waited-for process exited with that value or was killed by a signal. Since most utilities exit with small values, there is seldom any ambiguity. EXIT STATUS
If one or more parameters were specified, all of them have terminated or were not known by the invoking shell, and the status of the last parameter specified is known, then the exit status of wait is the exit status information of the command indicated by the last parameter specified. If the process terminated abnormally due to the receipt of a signal, the exit status is greater than 128 and is distinct from the exit status generated by other signals. (See the kill -l option.) Otherwise, the wait utility exits with one of the following values: The wait utility was invoked with no operands and all process IDs known by the invoking shell have terminated. The wait utility detected an error. The command identified by the last pid operand specified is unknown. EXAMPLES
Although the exact value used when a process is terminated by a signal is unspecified, if it is known that a signal terminated a process, a script can still reliably figure out which signal using kill as shown by the following script: sleep 1000& pid=$! kill -kill $pid wait $pid echo $pid was terminated by a SIG$(kill -l $?) signal. If either sequence of commands shown on the first two lines is run in less than 31 seconds either of the commands shown on lines 3 and 4 will return the exit sta- tus of the second sleep in the pipeline: sleep 257 | sleep 31 & jobs -l %% wait <pid of sleep 31> wait %% ENVIRONMENT VARIABLES
The following environment variables affect the execution of wait: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale used to affect the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. SEE ALSO
Commands: bg(1), csh(1), fg(1), jobs(1), kill(1), ksh(1), sh(1) Functions: wait(2) Standards: standards(5) wait(1)