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 the 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

  1. on the executable program with the --executable or -e option
    cpulimit -e program -l %cpu
  2. on the absolute path name of the file with the –path or -P option
    cpulimit -P path -l %cpu
  3.  on the PID of the process with the --pid or -p option
    cpulimit -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 background by using the --background or -b option

Click here to buy our VPS!

On this page