Linux: Use cpulimit to limit CPU usage

888u

Last update at :2024-07-14,Edit by888u

Introduction

cpulimit is a software that can limit CPU usage. It can limit a single specific program or the entire CPU usage. It is very easy to install and use. Friends who need it You can try;

Source installation (recommended)

Centos:

yum install cpulimit

Debian/Ubuntu:

apt-get install -y cpulimit

Compile and install

cd /tmp
wget 'https://www.02405.com/wp-content/uploads/2022/12/cpulimit-1.1.tar.gz'
tar cpulimit-1.1.tar.gz
cd cpulimit-1.1
make
cp cpulimit /usr/local/sbin/
rm -rf cpulimit*

Usage examples

Limit the program named xmrig to only use 60% of CPU usage and keep running in the background;

cpulimit -e xmrig -l 60 -b

Limit the program with process number 10086 to only use 60% of CPU utilization and keep running in the background;

cpulimit -p 10086 -l 60 -b

Limit the software under the absolute path to only use 60% of CPU utilization and keep running in the background;

cpulimit -e /usr/local/nginx/sbin/nginx -l 60 -b

Close the cpulimit background process (cancel all restrictions)

kill $(pidof cpulimit)

Instructions for use

-p –pid=N pid of the process PID of the process
-e –exe=FILE name of the executable program file Executable program file name
-P –path=PATH absolute path name of the Absolute path name of the process
-b –background run in background Running in the background
-l –limit=N percentage of cpu allowed from 1 up Allowed CPU percentage, minimum 1%
-z –lazy exit if there is no suitable target process Terminate if the target process exits or there is no target process
-h –help display this help and exit Show help and exit

Notes

  • The CPU percentage limit is based on the actual number of CPUs. For example, the maximum single-core is 100%, the maximum dual-core is 200%, the maximum three-core is 300%, and so on;
  • ROOT users can restrict all processes, while ordinary users can only restrict processes that the user has permission to manage;

Recommended site search: How to bind a domain name to a server, how to rent a server, active IP segments across the country, rental of registered domain names, how long does it take to register a website? Guangzhou server hosting, US high-defense space, virtual host, how to register a company domain name, check IP,

Linux: Use cpulimit to limit CPU usage

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码