参考:NICE, GETPRIORITY
getpriority()を使用したプライオリティの取得
nice()を使用したプライオリティの設定
setpriority()を使用したプライオリティの設定
実行結果
$ sudo ./getprio [sudo] ***** のパスワード: priority = 0 priority = -1 priority = 1
別ターミナルから確認
$ cat /proc/`pidof getprio`/sched | grep -e policy -e prio
getprio (105166, #threads: 1)
policy : 0
prio : 120
$ cat /proc/`pidof getprio`/stat | awk -F' ' '{print $18,$19}'
20 0
※ priority を -1 に設定後、確認
$ cat /proc/`pidof getprio`/sched | grep -e policy -e prio
getprio (105166, #threads: 1)
policy : 0
prio : 119
$ cat /proc/`pidof getprio`/stat | awk -F' ' '{print $18,$19}'
19 -1
※ priority を 1 に設定後、確認
$ cat /proc/`pidof getprio`/sched | grep -e policy -e prio
getprio (105166, #threads: 1)
policy : 0
prio : 121
$ cat /proc/`pidof getprio`/stat | awk -F' ' '{print $18,$19}'
21 1
$
| 優先度 | /proc/<pid>/sched | /proc/<pid>stat | |
| prio | priority | nice | |
| 高い | 100 | 0 | -20 |
| 119 | 19 | -1 | |
| デフォルト | 120 | 20 | 0 |
| 121 | 21 | 1 | |
| 低い | 139 | 39 | 19 |

