Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux – Bash:等到CPU使用率低于阈值大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

在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% 我该怎么办? 编辑:
在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版
>我正在虑平均cpu使用率(跨所有内核)

解决方法

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包.

大佬总结

以上是大佬教程为你收集整理的linux – Bash:等到CPU使用率低于阈值全部内容,希望文章能够帮你解决linux – Bash:等到CPU使用率低于阈值所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。