#author("2019-10-02T08:59:25+09:00","default:honma","honma") #author("2019-12-26T09:03:49+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) [[ソースコード:https://www.chobits.com/pukiwiki/index.php?plugin=attach&pcmd=open&file=sched_set_prio.c&refer=sched_setscheduler]] #ref(sched_set_prio.c) 実行結果 $ 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タスク)一覧 [#j9714410] |CENTER:|CENTER:|CENTER:|CENTER:|CENTER:|c |優先度|設定値|/proc/<pid>/sched|>|/proc/<pid>stat|h |~|~|prio|priority|nice|h |高い|99|0|-100|0| |低い|1|98|-2|0| ~ ~ #htmlinsert(amazon_pc.html);