Linux系统使用cpulimit限制进程CPU使用率
介绍
cpulimit 是一个限制进程的 CPU 使用率的工具(以百分比表示,而不是以 CPU 时间表示)。
当不希望批处理作业占用太多 CPU 时,控制批处理作业很有用。
目标是防止进程运行超过指定的时间比率。
它不会更改 nice 值或其他调度优先级设置,而是更改真实的 CPU 使用率,而且能够动态且快速地适应整个系统负载。
使用的 CPU 数量的控制是通过向进程发送 SIGSTOP 和 SIGCONT POSIX 信号来完成的。 指定进程的所有子进程和线程将共享相同百分比的 CPU。
源安装
yum install cpulimit
使用实例
nohup cpulimit -e nginx -l 90 -i &
开机启动
以linux系统为例,编辑/ect/rc.local文件
加入以下自启动命令
nohup cpulimit -e nginx -l 150 -i &
nohup cpulimit -e php-fpm -l 150 -i &
nohup cpulimit -e mysql -l 150 -i &
nohup cpulimit -e chrome -l 100 -i &
参数注释
-p | --pid=N | pid of the process | 进程的PID |
---|---|---|---|
-e | --exe=FILE | name of the executable program file | 可执行程序文件名 |
-P | --path=PATH | absolute path name of the | 进程的绝对路径名 |
-b | --background | run in background | 后台运行 |
-l | --limit=N | percentage of cpu allowed from 1 up | 允许的CPU百分比,最低为1% |
-z | --lazy | exit if there is no suitable target process | 如果目标进程退出或无目标进程则终止 |
-h | --help | display this help and exit | 显示帮助并退出 |
注意事项
- 限制CPU的百分比按照实际的CPU数量而定,比如单核最高为100%,双核最高为200%,三核最高为300%,以此类推即可;
- ROOT用户可以限制所有的进程,普通用户只能限制用户有权限管理的进程;
以上就是 cpulimit 这个小工具的一些基础用法和进阶用法,希望对大家有所帮助。
文章目录
关闭
共有 0 条评论