限制CPU使用率
Linux 中使用 cpulimit 限制进程在每单位时间内可以分配的 CPU 周期的比例
Linux 中使用 cpulimit 限制进程在每单位时间内可以分配的 CPU 周期的比例
::: code-group
$ dnf install cpulimit$ apt install cpulimit:::
$ cpulimit -hUsage: cpulimit [OPTIONS...] TARGET OPTIONS -l, --limit=N percentage of cpu allowed from 0 to 400 (required) -v, --verbose show control statistics -z, --lazy exit if there is no target process, or if it dies -i, --include-children limit also the children processes -h, --help display this help and exit TARGET must be exactly one of these: -p, --pid=N pid of the process (implies -z) -e, --exe=FILE name of the executable program file or path name COMMAND [ARGS] run this command and limit it (implies -z)
::: danger 特别注意
-l 在多核系统中,设置比例的时候,最大值不是100,而且 核心数*100
:::
例如4核服务器上有个进程id为15855的进程,我想限制它的CPU使用率为整体的80%,可以执行下面的命令:
$ cpulimit -l 320 -p 15855其中 320 为 400 * 80%