linux – Bash:等到CPU使用率低于阈值
发布时间:2020-12-13 19:33:46 所属栏目:Linux 来源:网络整理
导读:在bash脚本中,我需要等到CPU使用率低于阈值. 换句话说,我需要一个命令wait_until_cpu_low,我将这样使用: # Trigger some background CPU-heavy commandwait_until_cpu_low 40# Some other commands executed when CPU usage is below 40% 我该怎么办? 编辑
在bash脚本中,我需要等到CPU使用率低于阈值.
换句话说,我需要一个命令wait_until_cpu_low,我将这样使用: # Trigger some background CPU-heavy command wait_until_cpu_low 40 # Some other commands executed when CPU usage is below 40% 我该怎么办? 编辑: 目标操作系统是:Red Hat Enterprise Linux Server 6.5版 解决方法wait_for_cpu_usage() { current=$(mpstat 1 1 | awk '$12 ~ /[0-9.]+/ { print int(100 - $12 + 0.5) }') while [[ "$current" -ge "$1" ]]; do current=$(mpstat 1 1 | awk '$12 ~ /[0-9.]+/ { print int(100 - $12 + 0.5) }') sleep 1 done } 注意它需要安装sysstat包. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |