CPUTool – Limit and Control CPU Utilization of Any Process in Linux

One of the critical areas under Linux performance monitoring has to be CPU usage and system load. There are several Linux performance monitoring tools to keep an eye on how things are unfolding on a system.

A number of these tools simply output the system state/statistics while a few others provide you means of managing system performance. One such tool called CPUTool.

CPUTool is a simple yet powerful command-line tool for limiting and controlling CPU utilization of any process to a given limit and allows the interruption of process execution if the system load overreach a defined threshold.

How Does CPUTool Work?

In order to limit CPU usage, cputool sends the SIGSTOP and SIGCONT signals to processes and this is determined by the system load. It relies on the /proc pseudo-filesystem to read PIDs and their CPU usage measures.

It may be used to limit the CPU usage or system load influenced by a single process or a group of processes to a given limit and/or suspend processes if the system load goes beyond a threshold.

Suggested Read: Understand Linux Load Averages and Monitor Performance of Linux

Install CPUTool to Limit CPU Usage and Load Average

A CPUTool is only available to install on Debian/Ubuntu and its derivatives from the default system repositories using package management tool.

$ sudo apt install cputool

Limiting Process CPU Usage With CUPTool

Now lets look at how cputool really works. To demonstrate it all, we will run a dd command which should result into a high CPU percentage, in the background and display its PID.

# dd if=/dev/zero of=/dev/null &

To monitor CPU usage we can use the top or glances tools that allow us to view a real-time regularly updated state of a running Linux system processes:

# top
Monitor dd Command CPU Usage
Monitor dd Command CPU Usage

From the output above, we can see that dd command is having the highest percentage of CPU time 99.7%) Now we can limit this using cputool as shown below.

The --cpu-limit or -c flag is used to set a usage percentage for a process or group of processes and -p to specify a PID. The following command will limit the dd command (PID 8275) to 50% use of one CPU core:

# cputool --cpu-limit 50 -p 8275 

After running cputool, we can check the new CPU usage for the process (PID 8275) once more. Now the CPU usage for dd process should range from (49.0%-52.0%).

# top
Limit Process CPU to 50% Usage
Limit Process CPU to 50% Usage

To further limit dd’s CPU usage to 20%, we can run cputool for a second time:

# cputool --cpu-limit 20 -p 8275 

Then immediately check using tools such as top or glances like this (the CPU usage for dd should now range from 19.0%-22.0% or slightly beyond this):

# top
Limit Process CPU Usage to 20%
Limit Process CPU Usage to 20%

Note that the shell doesn’t expect any user input while cputool is running; therefore becomes unresponsive. To kill it (this will terminate the CPU usage limitation operation), press Ctrl + C.

Importantly, to specify a process group (one program with several running instances each with a distinct PID) for instance HTTP web server:

# pidof apache2
9592 3643 3642 3641 3640 3638 3637 1780

Use the -P flag like this:

# cputool --cpu-limit 20 -P 1780

Limiting System Load with CUPTool

The -l option is used to specify the maximum load the system may go though for the process or process group to continue running. We may use a fractional value (e.g. 2.5).

The example below means run rsync for a local backup only when the system load does not exceed 3.5:

# cputool --load-limit 3.5 --rsync -av /home/tecmint /backup/`date +%Y-%m-%d`/

For more information and usage, view the CPUTool man page:

# man cputool

Do check out following useful guides for finding CPU info and CPU performance monitoring:

  1. 9 Useful Commands to Get CPU Information on Linux
  2. Cpustat – Monitors CPU Utilization by Running Processes in Linux
  3. CoreFreq – A Powerful CPU Monitoring Tool for Linux Systems
  4. Find Top Running Processes by Highest Memory and CPU Usage in Linux

In conclusion, CPUTool really comes in handy for Linux performance management. Do share your thoughts about this article via the feedback form below.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

12 Comments

Leave a Reply
  1. Sorry for my English.

    I will use it on actual RaspiOS 64-bit (Pi4 2GB). Everything ends up with “User –help..“. It works fine on Pop! OS.

    What I tried:

    cputool --cpu-limit 20 -- htop
    Use --help for available options.
    cputool --load-limit 7.5 -- htop
    Use --help for available options.
    cputool -c 20 -- htop
    Use --help for available options.
    cputool -l 7.5 -- htop
    Use --help for available options.
    
    Reply
    • @FooBaa,

      It sounds like you’re experiencing an issue with cputool on RaspiOS that doesn’t occur on Pop! OS. Make sure that you’re using the correct syntax for the commands.

      You might also want to check if the version of cputool on RaspiOS is compatible or if there are any dependencies missing. Try running cputool --help for additional options and ensure everything is set up correctly.

      Let me know if you need more assistance!

      Reply
  2. The cputool is probably fine for some processes, but not for all of them. The 'dd' command is stopped when operated with ‘cputool‘ and this can be seen if the ‘dd‘ command is being run in the background and then issued a ‘jobs‘ command.

    Cputool stops the execution of some of the processes and therefore is not a good limiter of CPU utilization. The ‘cpulimit‘ package does the same.

    Reply
  3. I have downloaded cputool and cpulimit but this command “cputool –cpu-limit 20 -P 1780” is not working on my Ubuntu.

    Any reason why? It keeps bringing to me the --help page.

    Reply
    • @speedoelement

      The correct command is:
      #cputool – -cpu-limit 20 -p 1780

      Check the – -cpu-limit option, that is why it’s showing you the help page.

      Reply
  4. Hello, TecMint Team,

    Thanks for writing a wonderful article, I have a doubt. Can we limit uses of CPU in range?

    As I want to limit from 50-80% of CPU uses for dd command.

    Reply
    • @joe

      Good concern, we stated it as a range because after limiting CPU usage to a given percentage, the value will not just remain exactly at what you have set. It keeps on changing but remains either slightly lower or higher that the set value.

      Try out the examples provided in the guide, and watch using top or glances what happens after setting a certain percentage. Thanks.

      Reply

Got Something to Say? Join the Discussion...