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

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