【发布时间】:2016-06-28 19:53:55
【问题描述】:
这可能不是一个全新的话题,但我遇到了一些奇怪的情况。
通过在后台启动脚本,我正在循环处理大约 1000 个文件。我想根据每个进程返回的退出代码对文件采取一些措施。当我进入循环等待每个过程完成时,我发现一些过程已经完成。我将脚本修改为仅在 pgrep 找到进程时才等待,否则仅假设进程成功完成。问题是 - 我必须知道每个进程的退出代码才能对相应的文件采取行动。有什么想法吗?
pid_list=()
for FILE in $SOME_FOLDER
do
(process with FILE as parameter) &
done
for pid in "${pid_list[@]}"
do
if pgrep $pid; then #process could have just completed as we got here
if wait $pid; then
echo "process $pid successfully completed!" >> $logfile
else
echo "process $pid failed!" >> $logfile
fnc_error_exit
fi
else
echo "assumed that process $pid successfully completed but I DON'T KNOW THE EXIT CODE!" >> $logfile
continue
fi
done
【问题讨论】:
标签: process background ksh exit-code