setuid 创建一个子进程
setuid create one child process
当我尝试在我的程序中setuid
时,它会创建 2 个进程。 一个是父进程,另一个是子进程。
int isRoot()
{
if (getuid() != 0)
{
return 0;
}
else
{
return 1;
}
}
int main()
{
printf("%s n n",getUserName());
printf("%dn",getuid());
if(!isRoot())
{
printf("This program must be run as root/sudo user!!");
exit(0);
}
seteuid(1000);
while (1) {}
printf("%s n n",getUserName());
}
当我使用命令检查ps
它向我显示两个不同的过程时:
sagar@sagar-desktop:~$ ps -aef | grep a.out
root 20293 18135 0 15:36 pts/7 00:00:00 sudo ./a.out
sagar 20294 20293 99 15:36 pts/7 00:00:17 ./a.out
谁能告诉我为什么它创建两个进程而不是一个进程?
你错了。这就是sudo x
所做的。它在新进程中调用x
作为根并等待它,因此这两个进程。
不,这里只有一个流程副本。
root 20293 18135 0 15:36 pts/7 00:00:00 sudo ./a.out
这是sudo,而不是你的进程:./a.out是它的命令行参数。然后,它会将您的进程生成为子进程,正如您注意到的那样:
sagar 20294 20293 99 15:36 pts/7 00:00:17 ./a.out
相关文章:
- 终止 QProcess 不会终止子进程
- 什么时候最好在子进程中使用 CPU 或 I/O 密集型代码 [ C++ ]
- 子进程更新共享 mmap 内存,但父进程没有更改
- 使用 waitpid 时等待子进程终止
- 使用重定向标准处理子进程中的 kbhit
- 由 JOB 中的进程启动的子进程是否可以将 JOB 属性设置为脱离作业?
- 是否可以将子进程的 stdout 重定向到父进程中的另一个文件?
- kill() 总是返回 0(成功),即使在子进程已经结束之后?
- 父进程和子进程之间的 POSIX 信号量
- 检测到由于操作系统内存不足而导致子进程终止
- 使用system()创建独立的子进程
- 从stdin读取时子进程挂起(fork/dup2竞争条件)
- 从执事创建一个分叉进程
- 在 Bash 脚本中处理来自子进程的信号
- Qt C++ - 如何成功将数据传递给子进程?
- C++ 窗口本地系统模拟在子进程中失败
- 将类型化数组写入子进程 stdin 无法正常工作
- 如何将我的 cli 信息(变量等)共享到子进程,这是一个 bash shell 脚本
- 可以放置一个钩子来捕获由子进程发送到控制台的消息
- C++ 分叉子,向子进程询问进程列表,在 Linux 中杀死一个进程