Sponsored Content
Full Discussion: Wait Command
Top Forums Shell Programming and Scripting Wait Command Post 67819 by tmarikle on Monday 28th of March 2005 01:55:48 PM
Old 03-28-2005
Quote:
Originally Posted by lesstjm
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. Thanks.
Here is a section of a script that I am presently working on that loads several sqlldr threads that will each load a section of one data file (no, I can't use direct path Smilie ). I save each thread's PID and wait for all of them to finish. I use a sqlplus co-process to obtain load parameters so using "wait" without specifying PIDs wants to wait of the co-process to complete as well, which I cannot do. If I specify all of my PIDs to "wait", it would no wait for all of them to complete. I settled on a loop of my own that tests to see if the PIDs have finished running.

I save my return codes in a log file and parse it and the logs once everything is done to determine just what happed during the parallel load operation.

Code:
            # For each of the desired threads
            while [ ${SQLLDR_THREAD_COUNTER} -le ${SQLLDR_THREADS} ]
            do
...
                # Start a sqlldr thread and make it a background task
                {
                    # Run sqlldr task
                    print ${OLS_KEY} |
                              sqlldr ${OLS_USER}@${OLS_SID} \
                                     control=${CTL_FILE} \
                                     data=${UPLOAD_FILE} \
                                     errors=${SQLLDR_ERRORS} \
                                     rows=${SQLLDR_ROWS_IN_BIND_ARRAY} \
                                     bindsize=${SQLLDR_BINDSIZE} \
                                     direct=${SQLLDR_LOAD_USING_DIRECT_PATH} \
                                     silent=header,feedback \
                                     log=${LOG_FILE}_${SQLLDR_SKIP}.log \
                                     bad=${BAD_FILE}_${SQLLDR_SKIP}.bad \
                                     discard=${DSCRD_FILE}_${SQLLDR_SKIP}.dis \
                                     skip=${SQLLDR_SKIP} \
                                     load=${SQLLDR_ROWS_TO_LOAD} > /dev/null 2>&1

                    # Save exit status code in a temp file with all others
                    rc=$?
                    print "${SQLLDR_THREAD_COUNTER}:${rc}" >> ${SQLLDR_PARALLEL_RESULTS_FILE}

...
                } &

                # Save the background process ID
                PID_LIST="$PID_LIST $!,"
                # Compute next thread number
                ((SQLLDR_THREAD_COUNTER += 1 ))
            done

            #wait $PID_LIST
            # Simulate wait command since wait doesn't appear to wait for all
            # PIDs in $PID_LIST
            typeset THREAD_CNT=$(ps -p $(print ${PID_LIST} | tr -d ' ' | nawk '{print substr($0,1,length($0)-1)}') | wc -l)
            while [ $(( THREAD_CNT - 1 )) -gt 0 ]
            do
                update_process_status \
                     ${RUN_ID:-0} \
                     ${P_FN_CD} \
                     "InProgress" \
                     "staging ${FILE_TYPE} - sqlldr - threads still running: $(( THREAD_CNT - 1))" \
                     0
                sleep 2
                THREAD_CNT=$(ps -p $(print ${PID_LIST} | tr -d ' ' | nawk '{print substr($0,1,length($0)-1)}') | wc -l)
            done

I hope this helps; it works great for my needs.

Thomas
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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... (0 Replies)
Discussion started by: patrickk
0 Replies

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

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

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

10. 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
thr_join(3C)						   Standard C Library Functions 					      thr_join(3C)

NAME
thr_join - wait for thread termination SYNOPSIS
cc -mt [ flag... ] file...[ library... ] #include <thread.h> int thr_join(thread_t thread, thread_t *departed, void **status); DESCRIPTION
The thr_join() function suspends processing of the calling thread until the target thread completes. The thread argument must be a member of the current process and cannot be a detached thread. See thr_create(3C). If two or more threads wait for the same thread to complete, all will suspend processing until the thread has terminated, and then one thread will return successfully and the others will return with an error of ESRCH. The thr_join() function will not block processing of the calling thread if the target thread has already terminated. If a thr_join() call returns successfully with a non-null status argument, the value passed to thr_exit(3C) by the terminating thread will be placed in the location referenced by status. If the target thread ID is 0, thr_join() finds and returns the status of a terminated undetached thread in the process. If no such thread exists, it suspends processing of the calling thread until a thread for which no other thread is waiting enters that state, at which time it returns successfully, or until all other threads in the process are either daemon threads or threads waiting in thr_join(), in which case it returns EDEADLK. See NOTES. If departed is not NULL, it points to a location that is set to the ID of the terminated thread if thr_join() returns successfully. RETURN VALUES
If successful, thr_join() returns 0. Otherwise, an error number is returned to indicate the error. ERRORS
EDEADLK A joining deadlock would occur, such as when a thread attempts to wait for itself, or the calling thread is waiting for any thread to exit and only daemon threads or waiting threads exist in the process. ESRCH No undetached thread could be found corresponding to the given thread ID. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
thr_create(3C), thr_exit(3C), wait(3C), attributes(5), standards(5) NOTES
Using thr_join(3C) in the following syntax, while (thr_join(0, NULL, NULL) == 0); will wait for the termination of all non-daemon threads, excluding threads that are themselves waiting in thr_join(). SunOS 5.11 27 Mar 2000 thr_join(3C)
All times are GMT -4. The time now is 04:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy