安装cpu Usage Limiter for Linux
What is it?
cpulimit is a simple program that attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
可以限制程序使用CPU的百分比,而不是时间.很好,很舒服.
开始安装吧.
官方地址:http://cpulimit.sourceforge.net/
cd /root/install/
svn checkout https://cpulimit.svn.sourceforge.net/svnroot/cpulimit/trunkcpulimit ;
cd cpulimit
cp ./cpulimit /usr/sbin
如此简单,很愉快吧?
限制方法:
如果限制进程名,比如将httpd这个进程名的CPU限制在40%
cpulimit --exe httpd --limit 40
cpulimit --exe /usr/local/bin/httpd --limit 40
将pid为2960的进程的CPU限制在55%
cpulimit --pid 2960 --limit 55
慢慢对比top 命令那里的CPU变化.嘿嘿,有效果了吧?.
再来个完美的
自动限制当前进程使用CPU超过20%的进程,将他限制为10%
cpulimit --pid `ps aux|awk '{if($3 > 20) print $2}'` --limit 10
cpulimit命令:
Error: You must specify a target process, by name or by PID
Usage: cpulimit TARGET [OPTIONS...]
   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 absolute path name
   OPTIONS
      -l, --limit=N      percentage of cpu allowed from 0 to 100 (required)
      -v, --verbose      show control statistics
      -z, --lazy         exit if there is no suitable target process, or if it dies
      -h, --help         display this help and exit
---------------------
作者:woodcol
来源:CSDN
原文:blog.csdn.net/fengmm521/article/deTails/78446439 ;

 CentOS安装cpulimit限制某程序的CPU使用率

cpulimit 简介

cpulimit 命令的工作原理

为进程预设一个 cpu 占用率门限,并实时监控进程是否超出此门限,若超出则让该进程暂停运行一段时间。cpulimit 使用 SIGSTOP 和 SIGCONT 这两个信号来控制进程。它不会修改进程的 nice 值,而是通过监控进程的 cpu 占用率来做出动态调整。

cpulimit 的优势是可以控制进程的cpu使用率的上限值。但与 nice 相比也有缺点,那就是即使 cpu 是空闲的,进程也不能完全使用整个 cpu 资源。

CentOS 上,可以用下面的方法来安装它:

Bash

wget -O cpulimit.zip https://github.com/opsengine/cpulimit/archive/master.zipunzip cpulimit.zipcd cpulimit-mastermakesudocp src/cpulimit /usr/bin

上面的命令行,会先从从 github 上将源码下载到本地,然后再解压、编译、并安装到 /usr/bin 目录下。
现在就可以使用cpulimit命令了!
举例:

Bash

cpulimit –e httpd –l 40 #限制httpd(进程名)的cpu使用率为40%cpulimit –e /usr/local/bin/httpd –l 40cpulimit –p 2960 –l 55 #限制pid为2960的进程的CPU占用为55%

-e httpd, –exe=httpd,两者等同。
-l 40, –limit=40, 两者等同。
具体可以参考cpulimit -h帮助文档。

diannaobos.com/post/764.html

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。