Meniu

Limiting CPU usage by a process running Linux

Cpulimit is a small program written in C, which allows to limit the use of the processor through a Linux process. The specified limit is in percent so that we can avoid the maximum load as the processor generated by scripts, programs or processes.

I found it quite useful to use cpulimit, for crontab scripts, for example being able to back up overnight and so for archiving a 50GB file using gzip it will not use all the CPU resources and will remain for the other CPU processes.

In most Linux distributions, cpulimit is available, so you can use install using the following commands:

sudo apt-get install cpulimit

or

sudo yum install cpulimit

If it is not available to you, then you can easily compile it:

cd / usr / src /
wget - no-check-certificate by https:// github.com/opsengine/cpulimit/archive/master-Oppimim.tar
of xvf cpulimit.tar
CD-opsengine cpulimit-9df7758
do what
ln-s cpulimit / usr / sbin / cpulimit

From now on you can run cpulimit to limit the use of the processor by a process by percentage, the example below performs gzip archiving without exceeding the use of 10% of the CPU:

/ usr / sbin / cpulimit --limit = 10 / bin / gzip vzdump-openvz-102-2012_06_26-19_01_11.tar

You can check how much gzip you use in real time by ordering:

ps axu | grep [g] zip

or

top

The first command contains " grep [g] zip" to avoid the usual display of the last line:

root 896448 10.0 3.1 159524 3528? S 13:12 0:00 / usr / sbin / cpulimit --limit = 10 / bin / gzip vzdump-openvz-102-2012_06_26-19_01_11.tar
root 26490 0.0 0.0 6364 708 pts / 0 S + 15:24 0:00 grep gzip

Using cpulimit you can limit a process that is already running, the example below assigns a limit of 20% to the process with PID 2342:

/ usr / sbin / cpulimit -p 2342 -l 20

It is also possible to specify the executable instead of the PID:

/ usr / sbin / cpulimit -P / usr / sbin / nginx -l 30

FlorinM

Utilizator Linux - Solus OS, pasionat de calatorii.
  • | 2708 articole

Nici un comentariu inca. Fii primul!
  • powered by Verysign