#author("2019-05-30T18:06:58+09:00","default:honma","honma") * sched_setscheduler [#n60bd2aa] 参考:[[SCHED_SETSCHEDULER:https://linuxjm.osdn.jp/html/LDP_man-pages/man2/sched_setscheduler.2.html]] #highlight(c){{ #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; } }} #highlight(end) [[ソースコード:http://www.chobits.com/pukiwiki/index.php?plugin=attach&pcmd=open&file=sched_set_prio.c&refer=sched_setscheduler]] 実行結果 $ 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 $