LinuxでアプリケーションのCPU使用率を制限する方法(CPUlimit)
CPULimitは、Linuxで特定のアプリケーションのCPU使用率を制限するための単純なプログラムです。 デフォルトでは、Ubuntuリポジトリにあります。 Ubuntuで次のコマンドを発行してインストールできます。
sudo apt-get install cpulimit
出力
example@example:~$ sudo apt-get install cpulimit [sudo] password for example: 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) ... example@example:~$
アプリケーションのCPU使用率は、実行可能ファイル名またはプロセスID(pid)によって制限できます。 たとえば、Pythonで記述されたcronジョブがあります(名前= mycronjob.py、pid = 1234)
プロセス「mycronjob.py」を実行可能ファイル名で50%のCPU使用率に制限します
cpulimit -e mycronjob.py -l 50
PID(1234)によるプロセスを50%CPUに制限します。
cpulimit -p 1234 -l 50
これは、特定のアプリケーションがすべてのCPU使用率を使用するのを防ぐための非常に便利なプログラムです。