While administering your Linux system you need to limit the CPU usage of a process because it can consume more CPU usage and affects the performance of the whole system. This tutorial I will show how you can control CPU time of a process on Centos 7 and Ubuntu 16.
Refer Also : How to Limit Process at User Level on Linux
cpulimit is a nice command-line tool written in C programming language for limiting the CPU usage of a process. It is not present by default so we need to install it.
To install cpulimit on Ubuntu 16.04, do as below
# apt-get install cpulimit
Install on centos 7
# yum install epel-release # yum install cpulimit
We limit the CPU usage by using the
-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
cpulimit -e program -l %cpu
- on the absolute path name of the file with the
cpulimit -P path -l %cpu
- on the PID of the process with the
cpulimit -p process_pid -l %cpu
So, we will first check the process/program which consumes the CPU time
Then you can use the following command with the name of the program.
# cpulimit -e vmware-vmx -l 40 Process 3185 detected
You can see the tool has detected automatically the process id of the program. You can limit the cpu usage with the process id as below
# cpulimit -p 3185 -l 40 Process 3185 detected
And you can see the result below
You can run cpulimit in background by using the
You can use cputool which also uses cpulimit to reduce CPU usage.This can be also done by using the load limit. cputool is not present by default so you need to install it on Ubuntu 16
# apt install cputool
To use cputool, you need to respect the syntax below
cputool --cpu-limit %cpu -p process_pid
With the same example, you can use the cputool as below
# cputool --cpu-limit 30 -p 3185
The command will take the control of your terminal so you can use it in background as below:
# cputool --cpu-limit 30 -p 3185 &  16808
You can see the result as below
With these tools, you can easily control the CPU usage of a process when it is already running. You don't need to kill the processes to reduce the usage but you can simply assign a percentage to not exceed.