我正在嘗試編寫一個進程管理器,它使用實時調度策略SCHED_FIFO調度不同的進程。我想要做的是設置進程的優先級,並根據優先級執行它們。Linux進程調度程序
我有暫停的測試進程,並等待進程管理器恢復,以便他們執行他們的任務。
下面是測試過程中的部分代碼:
while(1) {
kill(myPid, SIGTSTP); // pause process until resumed by scheduler
printf("Process %s with PID %d and priority %d\n",
argv[0], myPid, param.sched_priority);
printf("Process %s processing...\n", argv[0]);
k = 0;
for (i = 0; i < 10000; i++) // do random task
{
for (j = 0; j < 10000; j++)
{
k++;
}
}
printf("Process %s done. Going to sleep.\n", argv[0]);
sched_yield(); // yield the processor
}
以下是進程管理器示例代碼:
pid_t child[3]; // holds child processes
while(1)
{
for (i = 0; i < num_child; i++)
{
kill(child[i], SIGCONT); // resume process
child_param.sched_priority = BASE_CHILD_PRIORITY + i * 10; // set priority
sched_setscheduler(child[i], SCHED_FIFO, &child_param); // set policy
}
}
雖然我能夠獲得最高的優先級先運行,這些進程在完成處理器之前不會完全完成任務。我的問題的輸出可以在下面看到。
Process 1 with PID 5975 and priority 79
Process 1 processing...
Process 2 with PID 5974 and priority 69
Process 3 with PID 5973 and priority 59
Process 2 processing...
Process 3 processing...
Process 1 done. Going to sleep.
Process 2 done. Going to sleep.
Process 3 done. Going to sleep.
爲什麼不SCHED_FIFO策略的過程中完成自己的任務的整個下道工序開始前?
這是對的'的sysctl -a單核電腦 – TheCodeArtist
?| grep sched_rt_'? – Olivier
輸出運行任何機會,這是一個多核CPU上運行... – ninjalj