Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 为什么setId()之前需要fork(),即使子进程不是组长?_Unix_Daemon - Fatal编程技术网

Unix 为什么setId()之前需要fork(),即使子进程不是组长?

Unix 为什么setId()之前需要fork(),即使子进程不是组长?,unix,daemon,Unix,Daemon,当我们创建守护进程时,我们都知道在setsid()之前使用fork()的原因是为了使子进程不是进程组负责人,因为我们需要调用setsid() 我的问题是,为什么父流程可能是流程组长?若fork()将使子进程不是进程组长,那个么为什么父进程是组长?因为父进程是由大进程分叉的,对吗 谢谢大家! 外壳可以做到这一点 交互式Shell将使每个执行的程序成为其自己的流程组长,以实现作业控制(命令的前置和后置) 以下是GNU文档的摘录: 由于每个进程都是分叉的,它应该通过调用setpgid[…]将自己放入新

当我们创建守护进程时,我们都知道在setsid()之前使用fork()的原因是为了使子进程不是进程组负责人,因为我们需要调用setsid()

我的问题是,为什么父流程可能是流程组长?若fork()将使子进程不是进程组长,那个么为什么父进程是组长?因为父进程是由大进程分叉的,对吗

谢谢大家!

外壳可以做到这一点

交互式Shell将使每个执行的程序成为其自己的流程组长,以实现作业控制(命令的前置和后置)

以下是GNU文档的摘录:

由于每个进程都是分叉的,它应该通过调用setpgid[…]将自己放入新的进程组中

if (shell_is_interactive)
  {
    /* Put the process into the process group and give the process group
     the terminal, if appropriate.
     This has to be done both by the shell and in the individual
     child processes because of potential race conditions.  */
  pid = getpid ();
  if (pgid == 0) pgid = pid;
  setpgid (pid, pgid);
  if (foreground)
    tcsetpgrp (shell_terminal, pgid);