To limit the CPU usage of a process on a Linux system, you can use the cpulimit
utility. cpulimit
is a command-line tool that allows you to limit the CPU usage of a process by specifying a percentage of CPU time that the process is allowed to use.
To install cpulimit
, you will need to use your system's package manager. On a Debian-based system, such as Ubuntu, you can use the following command:
sudo apt-get install cpulimit
On a Red Hat-based system, such as CentOS, you can use the following command:
sudo yum install cpulimit
Once cpulimit
is installed, you can use it to limit the CPU usage of a process by specifying the process ID (PID) and the desired CPU usage limit. For example, to limit the CPU usage of a process with PID 12345 to 50%, you can use the following command:
cpulimit -p 12345 -l 50
You can use the -e
option to specify the name of the executable file instead of the PID:
cpulimit -e myprocess -l 50
You can use the -b
option to run cpulimit
in the background:
cpulimit -b -e myprocess -l 50
You can use the -h
option to display a list of available options for the cpulimit
command.
Keep in mind that cpulimit
can only limit the CPU usage of processes that are running on the same system. It cannot limit the CPU usage of processes on remote systems.