How to Install and Use CPULimit to Monitor CPU in Linux

How to Install and Use CPULimit to Monitor CPU in Linux

Ever had a process on your Linux system go rogue and eat up all your CPU power? That can be super annoying — especially on servers or older computers. 😤 Fortunately, there’s a lightweight tool called cpulimit that lets you limit the CPU usage of specific processes without killing them. It’s like putting a leash on a hyperactive process.

In this guide, I’ll walk you through how to install and use cpulimit on Linux — even if you’re a beginner. Let’s get started!

What is cpulimit?

cpulimit is a simple command-line utility that allows you to limit the percentage of CPU usage for a specific process. Unlike nice or renice, which change the priority of a process, cpulimit actively pauses and resumes the process to keep its CPU usage under control.

Why Use CPULimit?

  • ⚙️ Prevent CPU hogging by background tasks.
  • 🖥️ Keep your system responsive while running heavy applications.
  • 🧪 Useful for testing CPU behavior at specific loads.
  • 🚀 Improve performance on systems with limited resources.

Step 1: Installing cpulimit

Installation depends on your Linux distro. Here’s how to get it on the most common ones:

For Ubuntu/Debian:

sudo apt update
sudo apt install cpulimit

For Fedora:

sudo dnf install cpulimit

For Arch Linux:

sudo pacman -S cpulimit

For CentOS/RHEL:

sudo yum install epel-release
sudo yum install cpulimit

Verify installation:

cpulimit --version

Step 2: Using cpulimit

Now that it’s installed, let’s see it in action. You can use cpulimit in a few ways:

Option 1: Limit a Process by PID

ps aux | grep [your_process_name]

Then apply cpulimit:

sudo cpulimit -p [PID] -l [CPU_LIMIT_PERCENTAGE]

Example:

sudo cpulimit -p 1234 -l 30

Option 2: Run a Command with Limited CPU

cpulimit -l [CPU_LIMIT] -- [your_command]

Example:

cpulimit -l 25 -- yes > /dev/null

Step 3: Run in the Background

cpulimit -p [PID] -l 30 &

Use jobs or ps to check if it’s still active.

Extra Tips 🔍

  • Use htop or top to monitor CPU usage visually.
  • Combine cpulimit with shell scripts to auto-limit specific tasks.
  • Works great with video encoding, backups, or mining processes.

Limitations of CPULimit

  • Only limits CPU, not memory or disk I/O.
  • Works best with single-threaded processes.
  • May not be available by default on all distros.

Conclusion

cpulimit is a handy little utility that gives you control over how much CPU power a process gets — without killing it. Whether you’re running a personal Linux desktop or managing a production server, it can help keep your system smooth and stable.

So go ahead, try it out, and take control of your CPU! 🔧🧠


Liked this guide? Share it or leave a comment if you want tutorials on other Linux tools. 💻🔥

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *