- 论坛徽章:
- 13
|
本帖最后由 _nosay 于 2016-03-24 18:15 编辑
书上说,只要还有实时进程在执行,就轮不到非实时进程执行,所以我做了一个实验。
① 写一个程序,设置调度策略为SCHED_RR,代码如下:- #include <stdio.h>
- #include <sched.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <errno.h>
- #include <string.h>
- int main()
- {
- struct sched_param param;
- param.sched_priority = sched_get_priority_max(SCHED_RR);
- printf("priority: %d\n", param.sched_priority);
- if (sched_setscheduler(getpid(), SCHED_RR, ¶m) < 0)
- {
- printf("%s\n", strerror(errno));
- return -1;
- }
- printf("%d\n", sched_getscheduler(getpid()));
- while (1) {
- // always TASK_RUNNING !!
- }
- return 0;
- }
复制代码 ② 再写一个程序,不设置调度策略,即按默认策略SCHED_OTHER调度,代码如下:- #include <stdio.h>
- #include <sched.h>
- #include <sys/types.h>
- #include <unistd.h>
- int main()
- {
- printf("%d\n", sched_getscheduler(getpid()));
- return 0;
- }
复制代码 ③ 编译程序①,用root身份执行(死循环),编译程序②,并执行。
期望:程序②等待程序①被kill时,才有机会执行printf()。
结果:不符合期望,程序②顺利执行完毕了。
请问如何理解“只要还有实时程序在执行,非实时程序就没有机会执行”?
http://www.cnblogs.com/zhaoyl/archive/2012/09/04/2671156.html |
|