Hack 101. Renice コマンド

renice は実行中プロセスのスケジューリングの優先順位を変更します。

実行中プロセスの優先順位を低くするには?(nice 値を増やす)

以下の例では、存在するシェルスクリプトが nice 値 10 で実行中です。(ps の出力の 6 番目のカラム)

$ ps axl | grep nice-test

0 509 13245 13216 30 10 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh


nice 値を増やす(優先順位を下げる)ために、以下に示すように renice コマンドを実行します。

$ renice 16 -p 13245

13245: old priority 10, new priority 16

$ ps axl | grep nice-test

0 509 13245 13216 36 16 5244 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

[Note: nice-test.sh (PID 13245) の 6 番目のカラムは nice 値が 16 になっています]

実行中プロセスの優先順位を高くするには?(nice 値を減らす)

以下に示すように、存在するシェルスクリプトが nice 値 10 で実行中です。(ps の出力の 6 番目のカラム)

$ ps axl | grep nice-test

0 509 13254 13216 30 10 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh

優先順位を上げるために、以下に示すように より小さい nice 値を指定します。
しかし、root だけが実行中プロセスの優先順位を上げることができます。
root 以外のユーザの場合は次のようなエラーメッセージが表示されます。

$ renice 5 -p 13254

renice: 13254: setpriority: Permission denied
Login as root to increase the priority of a running process

$ su -

# renice 5 -p 13254
13254: old priority 10, new priority 5

# ps axl | grep nice-test

0 509 13254 13216 25 5 4412 968 wait SN pts/1 0:00 /bin/bash ./nice-test.sh
[Note: 6番目のカラムは nice 値がより小さい 5 を示しています(優先順位が上がった)]