CPULimit est un programme simple permettant de limiter l’utilisation du processeur de certaines applications sous Linux. Il réside par défaut dans les référentiels Ubuntu. Nous pouvons l’installer en émettant la commande suivante dans Ubuntu
sudo apt-get install cpulimit
Sortie
mkyong@mkyong:~$ sudo apt-get install cpulimit[sudo]password for mkyong: Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: linux-headers-2.6.28-11 linux-headers-2.6.28-11-generic Use 'apt-get autoremove' to remove them. The following NEW packages will be installed: cpulimit 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 9730B of archives. After this operation, 65.5kB of additional disk space will be used. Get:1 http://my.archive.ubuntu.com jaunty/universe cpulimit 1.1-11[9730B]Fetched 9730B in 1s (8940B/s) Selecting previously deselected package cpulimit. (Reading database ... 131942 files and directories currently installed.) Unpacking cpulimit (from .../cpulimit__1.1-11__i386.deb) ... Processing triggers for man-db ... Setting up cpulimit (1.1-11) ... mkyong@mkyong:~$
Nous pouvons limiter l’utilisation du processeur de l’application par nom d’exécutable ou par id de processus (pid). Par exemple, nous avons un travail cron écrit en python (name = mycronjob.py, pid = 1234)
Limiter le processus ‘mycronjob.py’ par nom d’exécutable à 50% d’utilisation du processeur
cpulimit -e mycronjob.py -l 50
Limiter un processus par PID (1234) à 50% de l’UC:
cpulimit -p 1234 -l 50
C’est un programme très utile pour empêcher certaines applications d’utiliser toute notre utilisation du processeur :)
lien://tag/cpu/[cpu]lien://tag/unix/[unix]