












i=0
while true;do
# 此文件里面可以放同时执行的数量,也可将其替换成一个固定值
mod=$(cat process_count.plain.txt)
# 并行执行数量, 默认为3个进程执行
if [ -z "$mod" ]; then
mod=3
fi
if [ $((i % mod)) -eq "0" ]; then
echo "running $i"
# 关键在这里,需要等待上一批脚本执行完成
wait
fi
nohup sh your_script.sh >> your_script_${i}.log 2>&1 &
((i++))
done
Linux 中的 wait 命令用于等待子进程的状态变化,并获取有关状态变化的子进程的信息。状态变化包括:
wait [pid]
当子进程一直在执行的时候,wait会阻塞
如果接收到指定的信号后,会唤醒并向下执行
for pid in $(jobs -p); do
wait $pid
status=$?
if [ $status != 0 ]; then
echo " $pid status is $status have some error!" >> your_log
else
echo "$pid status is $status success!" >> your_log
fi
done
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。