sched_setscheduler†
参考:SCHED_SETSCHEDULER
- #include <stdio.h>
- #include <stdlib.h>
- #include <sched.h>
- #include <errno.h>
-
- void get_prio(void)
- {
- int ret;
- int policy;
- struct sched_param param;
-
- policy = sched_getscheduler(0);
- printf("policy = %d\n", policy);
-
- ret = sched_getparam(0, ¶m);
- if (ret == 0) {
- printf("sched_priority = %d\n", param.sched_priority);
- }
- else {
- perror("sched_getparam");
- }
- }
-
- void set_prio(int prio)
- {
- int ret;
- struct sched_param param;
-
- param.sched_priority = prio;
- ret = sched_setscheduler(0, SCHED_RR, ¶m);
- if (ret != 0) {
- perror("sched_setscheduler");
- }
- }
-
- int main(int argc, char **argv)
- {
- set_prio(1);
- get_prio();
-
-
- getchar();
-
- set_prio(99);
- get_prio();
-
-
- getchar();
-
- return 0;
- }
ソースコード
実行結果
$ sudo ./sched_set_prio
policy = 2
sched_priority = 1
policy = 2
sched_priority = 99
別のターミナルからプロパティを確認
※ 起動時のプライオリティは 1
$ cat /proc/`pidof sched_set_prio`/sched | grep -e policy -e prio
sched_set_prio (110053, #threads: 1)
policy : 2
prio : 98
$ cat /proc/`pidof sched_set_prio`/stat | awk -F' ' '{print $18,$19}'
-2 0
※ プライオリティを 99 に変更する
$ cat /proc/`pidof sched_set_prio`/sched | grep -e policy -e prio
sched_set_prio (110053, #threads: 1)
policy : 2
prio : 0
$ cat /proc/`pidof sched_set_prio`/stat | awk -F' ' '{print $18,$19}'
-100 0
$
設定値(RTタスク)一覧†
優先度 | 設定値 | /proc/<pid>/sched | /proc/<pid>stat |
prio | priority | nice |
高い | 99 | 0 | -100 | 0 |
低い | 1 | 98 | -2 | 0 |