In Linux, you can limit the CPU usage of a process by using the cpulimit command. Here’s how to use it:
- Install
cpulimiton your Linux system, if it is not already installed. You can do this using your distribution’s package manager. For example, on Ubuntu or Debian, you can run:sudo apt-get install cpulimit
- Identify the process ID (PID) of the process you want to limit. You can use the
pidofcommand to get the PID of a running process. For example, to get the PID of thefirefoxprocess, you can run:pidof firefox
- Use the
cpulimitcommand to limit the CPU usage of the process. The basic syntax of the command is as follows:cpulimit -l LIMIT -p PID
Replace
LIMITwith the maximum percentage of CPU usage you want to allow for the process, andPIDwith the PID of the process you want to limit.For example, to limit the
firefoxprocess to 50% CPU usage, you can run:cpulimit -l 50 -p $(pidof firefox)
This will limit the
firefoxprocess to using a maximum of 50% of the CPU.Note that
cpulimitworks by pausing and resuming the process at a given frequency, so the actual CPU usage may fluctuate around the limit you set. - If you want to remove the CPU usage limit, you can kill the
cpulimitprocess or use thekillall cpulimitcommand to kill allcpulimitprocesses.
That’s it! You have successfully limited the CPU usage of a process in Linux using cpulimit.