linux内核线程怎么设置优先级?
Linux內核的三種調度策略:
1,SCHED_OTHER 分時調度策略,
2,SCHED_FIFO實時調度策略,先到先服務。一旦占用cpu則一直運行。一直運行直到有更高優先級任務到達或自己放棄
3,SCHED_RR實時調度策略,時間片輪轉。當進程的時間片用完,系統將重新分配時間片,并置于就緒隊列尾。放在隊列尾保證了所有具有相同優先級的RR任務的調度公平 Linux線程優先級設置 首先,可以通過以下兩個函數來獲得線程可以設置的最高和最低優先級,函數中的策略即上述三種策略的宏定義: int sched_get_priority_max(int policy); int sched_get_priority_min(int policy); SCHED_OTHER是不支持優先級使用的,而SCHED_FIFO和SCHED_RR支持優先級的使用,他們分別為1和99,數值越大優先級越高?! ≡O置和獲取優先級通過以下兩個函數: int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *param); int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *param); 例如以下代碼創建了一個優先級為10的線程: struct sched_param { int __sched_priority; //所要設定的線程優先級 }; 例:創建優先級為10的線程 pthread_attr_t attr; struct sched_param param; pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_RR); param.sched_priority = 10; pthread_attr_setschedparam(&attr, ?m); pthread_create(xxx , &attr , xxx , xxx); pthread_attr_destroy(&attr);
總結
以上是生活随笔為你收集整理的linux内核线程怎么设置优先级?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux最大线程数?
- 下一篇: 安基游戏是什么?