bash - 如何为这个嵌套的 Bash 脚本使用超时?
问题描述
我编写了以下 bash 脚本,除了一些随机的时刻,它完全冻结并且不会进一步超过某个值,它工作正常a0
export OMP_NUM_THREADS=4
N_SIM=15000
N_NODE=1
for ((i = 1; i <= $N_SIM; i++))
do
index=$((i))
a0=$(awk "NR==${index} { print \$2 }" Intensity_Wcm2_versus_a0_10_20_10_25_range.txt)
dirname="a0_${a0}"
if [ -d "${dirname}" ]; then
cd -P -- "${dirname}" # enter the directory because it exists already
if [ -f "ParticleBinning0.h5" ]; then # move to next directory because the sim has been already done and results are there
cd ..
echo ${a0}
echo We move to the next directory because ParticleBinning0.h exists in this one already.
continue 1
else
awk -v s="a0=${a0}" 'NR==6 {print s} 1 {print}' ../namelist_for_smilei.py > namelist_for_smilei_a0included.py
echo ${a0}
mpirun -n 1 ../smilei namelist_for_smilei_a0included.py 2&> smilei.log
cd ..
fi
else
mkdir -p $dirname
cd $dirname
awk -v s="a0=${a0}" 'NR==6 {print s} 1 {print}' ../namelist_for_smilei.py > namelist_for_smilei_a0included.py
echo ${a0}
mpirun -n 1 ../smilei namelist_for_smilei_a0included.py 2&> smilei.log
cd ..
fi
done
我需要让它运行 12 个小时左右才能完成所有 15,000 次模拟。
一个mpirun -n 1 ../smilei namelist_for_smilei.py 2&> smilei.log
命令平均需要 4 秒才能运行。
有时它只是停在一个值上,屏幕上a0
最后一个打印的值是 say 。它保持这样,保持这样,无缘无故。从那个特别有问题的文件夹中没有写入任何输出。所以我不知道这个特殊值发生了什么。的任何值都不是特别重要,我可以不用计算 1 的特定值。a0
a0_12.032131
smilei.log
a0_12.032131
a0
a0
a0
我试图在 Ubuntu 中使用 timeout 实用程序以某种方式使其超过任何需要 2 分钟以上才能运行的 a0 值。如果运行时间超过此时间,它显然会失败并停止整个进程向前运行。
编写这样的脚本超出了我的能力范围。
我的特定管道的模板应该如何?
谢谢!
解决方案
看来这个mpirun
程序挂了。正如您所说,您可以timeout
在经过合理的时间后使用该实用程序终止其执行:
timeout --signal INT 2m mpirun...
根据mpirun
处理信号的方式,可能需要使用 KILL 而不是 INT 来终止进程。
推荐阅读
- json - 在 Angular 6 上使用随机属性名称解析 JSON
- python - 用于在文档中查找有意义的词对的 Python 工具
- html - 在具有可塑性列数的列中居中
- jquery - 隐藏/取消隐藏在后退按钮 html jquery iOS Chrome/Safari
- python - 当我另存为 CSV 时,文件包含两个分隔符,即逗号和管道
- docker - 错误的别名重定向
- stripe-payments - 在生产中保存客户时,在哪里可以找到 Stripe 的源令牌
- javascript - Javascript 对象样式模块到函数式编程
- wordpress - Wordpress如何设置ACF一次显示在所有页面上
- java - Recyclerview 在适配器外部更改项目颜色