How to Install and Use CPULimit to monitor CPU in Linux
Install cpulimit
To install cpulimit on Ubuntu, do as below
apt-get install cpulimit
Install on Centos 7
install epel-release install cpulimit
We limit CPU usage by using the --limit
or -l
option to set a usage percentage for a process. Before limiting the CPU usage, you need to find the process or the command that is using all your CPU time
There are three ways to use cpulimit by acting
- on the executable program with the
--executable
or-e
optioncpulimit -e program -l %cpu
- on the absolute path name of the file with the –path or
-P
optioncpulimit -P path -l %cpu
- on the PID of the process with the
--pid
or-p
optioncpulimit -p process_pid -l %cpu
So, we will first check the process/program which consumes the CPU time
# top
You can limit the CPU usage with the process id as below
# cpulimit -p 31177 -l 60 Process 31177 found
And you can see the result below
You can run cpulimit in the background by using the --background
or -b
option