Linux Limit CPU Usage Per Process

In Linux, you can limit the CPU usage of a process by using the cpulimit command. Here’s how to use it:

  1. Install cpulimit on 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
  2. Identify the process ID (PID) of the process you want to limit. You can use the pidof command to get the PID of a running process. For example, to get the PID of the firefox process, you can run:
    pidof firefox
  3. Use the cpulimit command to limit the CPU usage of the process. The basic syntax of the command is as follows:
    cpulimit -l LIMIT -p PID

    Replace LIMIT with the maximum percentage of CPU usage you want to allow for the process, and PID with the PID of the process you want to limit.

    For example, to limit the firefox process to 50% CPU usage, you can run:

    cpulimit -l 50 -p $(pidof firefox)

    This will limit the firefox process to using a maximum of 50% of the CPU.

    Note that cpulimit works by pausing and resuming the process at a given frequency, so the actual CPU usage may fluctuate around the limit you set.

  4. If you want to remove the CPU usage limit, you can kill the cpulimit process or use the killall cpulimit command to kill all cpulimit processes.

That’s it! You have successfully limited the CPU usage of a process in Linux using cpulimit.

Leave a Comment