Skip to main content

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

Comments

Anonymous said…
Why wouldn't you simply use limits.conf for this ?
Anonymous said…
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
W said…
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.
David Esquivel said…
Thank you very much.
I think the first example should be:

cpulimit -e firefox -l 30

Popular posts from this blog

How to install Skype on Ubuntu 10.04 Lucid Lynx

UPDATE: Skype has now been uploaded to the "partner" official Ubuntu 10.04 Lucid Lynx repository. See Install Skype in Ubuntu 10.04 Lucid Lynx from official partner repository Command Line way Get the package: For 32-bit $ wget http://www.skype.com/go/getskype-linux-beta-ubuntu-32 For 64-bit $ wget http://www.skype.com/go/getskype-linux-beta-ubuntu-64 You will need to install the following libraries. $ sudo apt-get install libqt4-dbus libqt4-network libqt4-xml libasound2 Now install skype(the file u just downloaded, may be named intrepid-ibex) $ sudo dpkg -i skype-XXXXXXXXXXXX.deb If you still get some dependency error then just type the command below $ sudo apt-get -f install this will install the dependencies and the skype. Non - Terminal Download the setup 32 -bit 64 -bit You will these packages: libqt4-dbus libqt4-network libqt4-xml . Goto Synaptic manager and install them. Now Launch the Skype install .deb file (just double click it) and follow the on screen prompts....

gtalx: Howto Gtalk in ubuntu ( google talk )

Did you fail to use " gtalk in ubuntu " ... Now you can chat and talk to your gmail buddies in ubuntu... 1. check for gtk2.0 and qt4 $ sudo apt-get install libgtk2.0-dev $ sudo apt-get install libqt4-dev libogg-dev libtheora-dev $ sudo apt-get install libsdl-dev libavcodec-dev libswscale-dev $ sudo apt-get install libexpat-dev libraw1394-dev libvorbis-dev $ sudo apt-get install libgsm1-dev  libspeexdsp-dev libmediastreamer0-dev libortp-dev 2. Remove 'pulse audio sound server' Open synaptic package manager and remove pulse audio 3. "Download gtalx" from here Dowload it here 4. Extract the file.... $ tar -zxvf 0.0.4.tar.gz 5. Get into the directory.... $ cd 0.0.4 and then... $ sudo chmod u+x make $ ./make $ sudo ./make install 6. Enjoy..... Please comment about your installation(whether it was a success or not....) Take gtalx from Applications > Internet > gtalx Enter your gmail login information..and click connect... ...

How to install Skype on Ubuntu 9.10 Karmic Koala

The two methods  below doesn't work now. Please see http://blog.dipinkrishna.info/2009/11/how-to-download-and-install-skype-for_3060.html for a successfull installation of skype on ubuntu. I have provided two methods. Please do comment which one is successful. Follow these steps to install skype in ubuntu 9.10 (64 bit).         First add:             deb http://packages.medibuntu.org/ karmic free non-free         to your source.list Now open a terminal and type: $ sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list Then do an update: $ sudo apt-get update $ sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring $ sudo apt-get -q update And finally install Skype. $ sudo apt-get install skype Ready ... now start skype with $ skype OR Download the setup 32 -bit 64 -bit Launch the Skype i...