0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[CentOS 8]プロセスの優先度設定(メモ)

Posted at

nice値

CentOS(RHELも同じだと思う)のプロセスの優先度はnice値で設定する。各プロセスのnice値は親プロセスの値を継承し、通常は「0」
nice値は-20から19までの40段階で設定され、値が小さいほど優先度が高くなる。

設定と動作

負荷をかける。

$ sha1sum /dev/zero &
[1] 2155
$ ps u |grep sha1
user01      2155 94.8  0.0  16852  1772 pts/0    R    10:16   1:33 sha1sum /dev/zero
user01      2183  0.0  0.0  10280  1056 pts/0    S+   10:18   0:00 grep --color=auto sha1

100%近くまでCPUを消費している。


nice値「10」(優先度低)のインスタンスを起動する。

$ nice -n 10 sha1sum /dev/zero &
[2] 2184
$ ps -o pid,pcpu,nice,comm
    PID %CPU  NI COMMAND
   2016  0.0   0 bash
   2155 93.2   0 sha1sum
   2184  9.5  10 sha1sum
   2187  0.0   0 ps

nice値「0」のプロセスが優先されるので、nice値「10」のプロセスの負荷は上がらない。


PIDを指定してnice値を「10」から「-10」に変更する。

$ sudo renice -n -10 2184
2184 (process ID) 従来の優先順位は 10 で, 新しい優先順位は -10 です

しばらく待つと、nice値が低い(優先度が高い)プロセスの負荷が高くなる。

$ ps -o pid,pcpu,nice,comm
    PID %CPU  NI COMMAND
   2016  0.0   0 bash
   2155 37.0   0 sha1sum
   2184 74.3 -10 sha1sum
   2262  0.0   0 ps
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?