LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 876|回复: 4

麻烦诸位帮忙跑个程序

[复制链接]
发表于 2007-3-5 22:50:14 | 显示全部楼层 |阅读模式
下面的程序是有关进程调度的,程序试图将一个普通进程赋予较高的优先级。

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <sys/time.h>
  7. #include <sys/resource.h>
  8. #include <sched.h>

  9. int main()
  10. {
  11.     uid_t iUID;
  12.     struct sched_param sSchedParam;
  13.     struct rlimit * psLimit;

  14.     iUID = getuid();
  15.     setuid(0);

  16.     getrlimit(RLIMIT_NICE, psLimit);
  17.     printf("struct rlimit: rlim_cur = %d, rlim_max = %d\n", psLimit->rlim_cur, psLimit->rlim_max);
  18.     if(psLimit->rlim_max == 0)
  19.     {
  20.         psLimit->rlim_max = -1;
  21.         if(setrlimit(RLIMIT_NICE, psLimit) != 0)
  22.             printf("Failed to setrlimit: %s\n", strerror(errno));
  23.     }

  24.     sSchedParam.sched_priority = 1;
  25.     if (sched_setscheduler(0, SCHED_FIFO, &sSchedParam) == -1)
  26.     {
  27.         printf("Failed to set scheduling parameters: %s\n", strerror(errno));
  28.     }
  29.     setuid(iUID);
  30. }
复制代码

在我的系统中的执行结果:

  1. struct rlimit: rlim_cur = 0, rlim_max = 0
  2. Failed to setrlimit: Operation not permitted
  3. Failed to set scheduling parameters: Operation not permitted
复制代码

从网上搜到有的系统(ubuntu)的rlim_max = -1,因此没有Operation not permitted那项。

麻烦哪位好心人把系统情况和运行输出告诉我。谢谢!

我的系统:

  1. $ uname -a
  2. Linux RAYS 2.6.17-2-686 #2 SMP Mon Aug 28 15:33:43 CST 2006 i686 GNU/Linux
复制代码
发表于 2007-3-6 08:06:22 | 显示全部楼层
运行结果:
  1. [aaron@localhost tcp]$ ./helpshuixin
  2. struct rlimit: rlim_cur = 1474660693, rlim_max = -326937770
  3. Failed to set scheduling parameters: Operation not permitted
  4. [aaron@localhost tcp]$ uname -a
  5. Linux localhost.localdomain 2.6.15-1.2054_FC5 #1 Tue Mar 14 15:48:33 EST 2006 i686 i686 i386 GNU/Linux
  6. [aaron@localhost tcp]$
  7.    
复制代码
回复 支持 反对

使用道具 举报

发表于 2007-3-6 08:12:49 | 显示全部楼层

  1. rf@debian:~/shm$ gcc t.c
  2. rf@debian:~/shm$ ./a.out
  3. struct rlimit: rlim_cur = 18589, rlim_max = 85472
  4. Failed to set scheduling parameters: Operation not permitted
复制代码

但若用 root 执行则不会错误



  1. rf@debian:~/shm$ uname -a
  2. Linux debian 2.6.18 #1 Sun Feb 25 01:37:19 CST 2007 i686 GNU/Linux
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-6 11:33:40 | 显示全部楼层
谢谢二位,我再好好研究研究
回复 支持 反对

使用道具 举报

发表于 2007-3-12 15:55:19 | 显示全部楼层
you need to be root to run this programm :cool:
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表