首页域名资讯 正文

使用CPULIMIT来限制进程的CPU利用率

2024-10-07 1 0条评论

 

安装cpulimit

1 # yum install cpulimit

使用cpulimit进行cpu利用率限制

1. 先了解一下cpulimit的参数

1 2 3 4 5 6 7 8 9 10 11 12 # cpulimit -h Usage : cpulimit [ OPTIONS . . . ] TARGET    OPTIONS        l , limit = N            percentage of cpu allowed from 0 to 100 ( required ) //cpu限制的百分比        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 ) //进程的pid        e , exe = FILE         name of the executable program file or path name //可执行程序        COMMAND [ ARGS ]          run this command and limit it ( implies z )

2. 根据进程ID限值

1 # cpulimit -p 1234 -l 40

此命令的含义为,限制pid号为1234的进程,最高只能使用40%的cpu。

3. 根据进程路径限制

1 # cpulimit -e /usr/local/nginx-1.4.1/sbin/nginx -l 50

限制nginx程序只能使用最高50%的cpu。

注意事项

  1. -l后面限制的cpu使用量,要根据实际的核心数量而成倍减少。比如上文中的进程1234,40%的限制生效在1核服务器中,如果是双核服务器,则应该限制到20%,四核服务器限制到10%以此类推。
  2. root用户可以限制所有的进程,普通用户只能限制自己有权限管理的进程。

文章转载来自:trustauth.cn

文章版权及转载声明

本文作者:亿网 网址:https://edns.com/ask/post/150700.html 发布于 2024-10-07
文章转载或复制请以超链接形式并注明出处。