免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1586 | 回复: 2
打印 上一主题 下一主题

[C] 麻烦帮看下是什么错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-04-25 16:33 |只看该作者 |倒序浏览
本帖最后由 daodaohu123 于 2013-04-25 16:33 编辑
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <sys/types.h>
  6. #include <errno.h>

  7. int main(){
  8.         pid_t pid;

  9.         printf("current [pid]%d [ppid]%d [gid]%d [pgid]%d\n", getpid(), getppid(), getgid(), getpgid(getppid()));
  10.         if(pid = fork() > 0){
  11.                 printf("parent process is exit\n");
  12.                 exit(EXIT_SUCCESS);
  13.         }
  14.         else if(-1 == pid){
  15.                 printf("%dL[%d]: %s \n", __LINE__, errno, strerror(errno));
  16.                 exit(EXIT_FAILURE);
  17.         }

  18.         if(setsid() < 0){
  19.                 printf("%dL[%d]: %s \n", __LINE__, errno, strerror(errno));
  20.                 exit(EXIT_FAILURE);
  21.         }

  22.         if(setpgrp() < 0){
  23.                 printf("%dL[%d]: %s \n", __LINE__, errno, strerror(errno));
  24.                 exit(EXIT_FAILURE);
  25.         }

  26.         printf("alter [pid]%d [ppid]%d [gid]%d [pgid]%d\n", getpid(), getppid(), getgid(), getpgid(getppid()));

  27.         return EXIT_SUCCESS;
  28. }
复制代码
信息提示:29L[1]: Operation not permitted

我感觉是不是setpgrp()操作权限不够的原因,应该怎么处理

论坛徽章:
0
2 [报告]
发表于 2013-04-26 07:48 |只看该作者
setsid()会使当前子进程为组长进程,然后调用setpgrpp(),也是设置为组长进程,重复。

论坛徽章:
0
3 [报告]
发表于 2013-04-26 09:37 |只看该作者
本帖最后由 daodaohu123 于 2013-04-26 09:52 编辑

回复 2# younghuster


    可是当我把setpgrp()去掉后  获得的GID和在函数最开始获得的GID是一样的并且该组的GID是1000(我在/etc/passwd下找到了锁定硬的程序为/bin/bash),那是不是就不能通过上边的代码设置组长
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP