Skip to main content

How To Limit CPU Usage Per Process

You can use the cpulimit to limit the real time cpu usage of a process. This limitation of cpu usage is done in term of percentage and not in term of cpu time. cpulimit only act on the real cpu usage and not any scheduling criteria or nice value. cpulimit has been made to adapt itself dynamically to the overall system load.

Steps to Install cpulimit:

# cd /tmp
# wget 'http://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz'
# tar cpulimit-1.1.tar.gz
# cd cpulimit-1.1
# make
# cp cpulimit /usr/local/sbin/
# rm -rf cpulimit*


For Debian / Ubuntu Linux users. Type the following command to install cpulimit:

$ sudo apt-get update
$ sudo apt-get install cpulimit



How do I use cpulimit?

To limit CPU usage of the process called firefox to 30%, enter:
# cpulimit -e firefox -l 30

To limit CPU usage of the process to 30% by using its PID, enter:
# cpulimit -p 1313 -l 30

NOTE :

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.

Note (Multicore / MultiCpu) Systems

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.

Comments

Popular posts from this blog

Singly Linked List

/**     Program Name: Singly Linked List     Description: This Program is for Implemeting Singly Linked List     Author:  Tauqirul Haque         */ struct Linklist {     int item;     struct Linklist *next; }; typedef struct Linklist node; void insertAtBeginning(node **); void createAppendNode(node **); void insertInMiddle(node **); void deleteNode(node **); void displayNode(node **); void countNode(node **);  void searchElement(node **); void reverse(node **); void main() {     node *head = NULL;     int choice = 0;     while(choice != 9)     {             printf("\n\t\t\t1. Add Node At The Beginning ");     printf("\n\t\t\t2. Insert Element in the Middle ");     printf("\n\t\t\t3. Append New Node "); ...

SWAP Two Values without using temporary variable

/**     Program Name: Swap Two Numbers     Description: This Program swaps two number, using XOR     Author:  Tauqirul Haque        */ #include <stdio.h> #include <conio.h> int main() {     int firstNumber, secondNumber;        printf("Enter The First Number :  ");     scanf("%d",&firstNumber);        printf("\nEnter The Second Number :  ");     scanf("%d",&secondNumber);        printf("\n\nNumbers Before Swapping :  %d  <-> %d \n",firstNumber, secondNumber);        firstNumber = firstNumber^secondNumber;     secondNumber = firstNumber^secondNumber;     firstNumber = firstNumber^secondNumber;        printf("\nNumbers After Swapping : ...

Linux User Survey

The most popular distro is Mandriva, with 17.9% of the respondents using it, followed by Suse, with 16.2%. The most popular application is Firefox, with 47.9% of the respondents using it, followed by OpenOffice, with 31.6% and Thunderbird, with 12.0%. Also appended below is a table with the break-down of the survey participants by country. Top Distros 1 Mandriva 17.9% 2 Suse 16.2% 3 Fedora 11.1% 4 Debian 7.7% 5 Red Hat 6.8% 6 Xandros 5.1% 7 Slackware 5.1% 8 Ubuntu 3.4% 9 Centos 3.4% 10 Mepis 3.4% 11 Gentoo 3.4% 12 Knoppix 2.6% 13 Linspire 1.7% 1...