processUsageFile()
{
#sdate=`pin_virtual_time | awk -F" " '{print $3}'`;
#Get all new files to be loaded to brm staging data.
count=`ls ${PRE_STAGING}/TWN* 2>/dev/null|grep -v reprocess|wc -l`
if [ $count -ne 0 ];then
# Fork subshell
(./efx_omc_brm_rpt_process.sh -t TWN & )&
exitOnError
fi
#Process Rapid Report files
count=`ls $PRE_STAGING/RR* 2>/dev/null|grep -v reprocess|wc -l`
if [ $count -ne 0 ];then
(./efx_omc_brm_rpt_process.sh -t RR &)&
exitOnError
fi
...
...
}
#Reprocessing. Process the reprocessed files.
#This method updates the records in the BRM staging table.
reprocessingUsageFile()
{
#Process TWN fulfillment reprocess files
count=`ls $PRE_STAGING/TWN*reprocess* 2>/dev/null|wc -l`
if [ $count -ne 0 ];then
# Fork subshell
(./efx_omc_brm_rpt_reprocess.sh -t TWN & ) &
fi
#Process Rapid Report files
count=`ls $PRE_STAGING/RR*reprocess* 2>/dev/null|wc -l`
if [ $count -ne 0 ];then
(./efx_omc_brm_rpt_reprocess.sh -t RR &) &
fi
...
...
}
#Pre processing
PreProcessing
# Start processing usage files.
processUsageFile
processErrFile
以上代码的想法是进行并行处理。所有方法都会调用多个子shell并从tty分离。我想知道是否有办法在等待前两个方法先完成执行,然后再运行最后一个方法。
等待PID并不太准确。仍在尝试中...
waitPids() {
echo "Testing $pids -- ${#pids[@]}"
while [ ${#pids[@]} -ne 0 ]; do
local range=$(eval echo {0..$((${#pids[@]}-1))})
local i
for i in $range; do
if ! kill -0 ${pids[$i]} 2> /dev/null; then
echo "Done -- ${pids[$i]}"
unset pids[$i]
fi
done
pids=("${pids[@]}")
sleep 1
done
}
wait
有帮助吗? - Etan Reisner