Why fork() before setsid()

前端 未结 3 738
旧巷少年郎
旧巷少年郎 2021-01-29 21:48

Why fork() before setsid() to daemonize a process?

Basically, if I want to detach a process from its controlling terminal and make it a process

3条回答
  •  不知归路
    2021-01-29 22:44

    It is required to fork() and have the child call setsid() to ensure that the process calling setsid() isn't already a process group leader (setsid() wants to make the calling process the process group leader of a new process group, so it fails in that case).

提交回复
热议问题