下面的程序是有关进程调度的,程序试图将一个普通进程赋予较高的优先级。
- #include <string.h>
- #include <stdio.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/time.h>
- #include <sys/resource.h>
- #include <sched.h>
- int main()
- {
- uid_t iUID;
- struct sched_param sSchedParam;
- struct rlimit * psLimit;
- iUID = getuid();
- setuid(0);
- getrlimit(RLIMIT_NICE, psLimit);
- printf("struct rlimit: rlim_cur = %d, rlim_max = %d\n", psLimit->rlim_cur, psLimit->rlim_max);
- if(psLimit->rlim_max == 0)
- {
- psLimit->rlim_max = -1;
- if(setrlimit(RLIMIT_NICE, psLimit) != 0)
- printf("Failed to setrlimit: %s\n", strerror(errno));
- }
- sSchedParam.sched_priority = 1;
- if (sched_setscheduler(0, SCHED_FIFO, &sSchedParam) == -1)
- {
- printf("Failed to set scheduling parameters: %s\n", strerror(errno));
- }
- setuid(iUID);
- }
复制代码
在我的系统中的执行结果:
- struct rlimit: rlim_cur = 0, rlim_max = 0
- Failed to setrlimit: Operation not permitted
- Failed to set scheduling parameters: Operation not permitted
复制代码
从网上搜到有的系统(ubuntu)的rlim_max = -1,因此没有Operation not permitted那项。
麻烦哪位好心人把系统情况和运行输出告诉我。谢谢!
我的系统:
- $ uname -a
- Linux RAYS 2.6.17-2-686 #2 SMP Mon Aug 28 15:33:43 CST 2006 i686 GNU/Linux
复制代码 |