Skip to content
Blog Limiting the CPU usage of applications on Linux (ubuntu, debian, fedora etc.)

Limiting the CPU usage of applications on Linux (ubuntu, debian, fedora etc.)

Monitor the CPU usage of applications that we use, it is recommended if you need to maintain a good performance on your system, sometimes in our system we have applications that should not stop working and we need some free resources on your computer for them. Linux can prevent other applications to consume these resources and the applications work properly within a cpu limit.

To install in ubuntu:

$ sudo apt-get install cpulimit
It is in the universe repositories.

To install it on any other Linux distribution follow this:

$ wget http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz
$ tar-zxf cpulimit * xxx.tar.gz
$ cd cpulimit-xxx
$ make


Use it

To use it, you will need to know the name of the application or PID, once you know it:
Examples of use

If we want to avoid that Firefox does not exceed 30% of CPU usage type
cpulimit -e firefox -l 30

In the case of wanting to limit the process with PID 3675 to use only 40% CPU at maximum, for that type on your console as follows:
cpulimit-p 3675-l 40

You can also add the full path of your application:
cpulimit-P / l usr/lib/firefox-3.0.11/firefox-30

Limit the process ‘bigloop’ by executable name to 40% CPU:
cpulimit –exe bigloop –limit 40
cpulimit –exe /usr/local/bin/bigloop –limit 40

Limit a process by PID to 55% CPU:
cpulimit –pid 2960 –limit 55

Launch a process by command line and limit it to 40% (in development version only!):
cpulimit –limit 40 /etc/rc.d/rc.boinc start

cpulimit -e applicationname -l 30 o cpulimit -p PID -l 40


Notes:

If your machine has one processor you can limit the percentage from 0% to 100%, which means that if you set for example 50%, your process cannot use more than 500 ms of cpu time for each second. But if your machine has four processors, percentage may vary from 0% to 400%, so setting the limit to 200% means to use no more than half of the available power. In any case, the percentage is the same of what you see when you run top.

cpulimit should run at least with the same user running the controlled process. But it is much better if you run cpulimit as root, in order to have a higher priority and a more precise control.
Now cpulimit does limit also the children of the specified process. The code is still experimental, so let me know how it is.

Official Website: CPU Limit

4 thoughts on “Limiting the CPU usage of applications on Linux (ubuntu, debian, fedora etc.)”

  1. Thanks. But do you know how to limit memory and CPU for a user or a group of users and not only a process. I know that you can use limit.conf, but this limits applies to single processes of a user or a group, but it does not limit how much memory a single user can use in total.

  2. Hi All,

    My client is a global fast-growing IT automation software company based in Milpitas. They are currently seeking an experienced Linux developer with C++ programming knowledge to help grow their engineering team. The environment is very collaborative and dynamic – no top down management styles here. Competitive comp and performance-based bonus package!

    Here is a job description. If you have the skill set and you are interested in hearing more about this opportunity, please email me your updated resume.

    Responsibilities:
    • As a senior member of the engineering team, you will work closely with small development team making design decisions for a Linux version of our Agent.
    • Assume a lead role in designing, coding, and testing an Agent ported to the Linux platform. The Agent communicates via TCP/IP to a remote Windows server hosting our Server management service. The server sends down command primitives to the Agent to perform rudimentary tasks such as writing a file, getting a file, executing a file, auditing the hardware and software on the PC, prompting a user with question and waiting for a response, rebooting, monitoring resources, and more. These rudimentary commands are combined to perform management tasks, such as remote controlling the PC, deploying patches, monitoring the resource utilization of the PC, installing programs, enforcing policies, and more.
    • Design and implement an Agent installation package and update package for the Linux platform.
    • Contribute to the definition of product features to the Agent for ongoing enhancements to the management of Linux computer systems.
    • Provide 2nd tier support for the Linux Agent and its components
    • Features are chosen to fit our product releases and upgrades which occur every 4 to 6 months. Typical features are designed, implemented, and tested in periods lasting as short as days to a month depending on the scope. Daily design decisions must always be cognizant of robustness, scalability, minimal resource utilization, and backwards compatibility as the Agent resides on every managed PC deployed.
    Requirements:
    • 10+ years software development experience in Linux/UNIX with 5+ years experience specifically with Linux development across various distributions (Ubuntu, RedHat, Debian, SUSE,etc).
    • Expertise in the following areas
    o Client-server, multi-threaded Linux application development
    o Development of system level services on the Linux
    o C/C++ Code development
    o TCP/IP communications
    o Inter-process communications
    o Working knowledge of Linux OS internals
    o Development of an application installer on the Linux platform
    • BS in Computer Science
    • The following are preferred skills and qualifications, but not required
    o Cross platform code development between Windows and Linux environments
    o Cross platform code development between Mac OS X and Linux environments
    o Cross platform code development between UNIX (Solaris, HP-UX, AIX, etc) and Linux environments
    o Driver development on Linux

    email me with your resume jill@ascendantstaffing.com

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.