擅长:python、mysql、java
<p>看看问题中引用的代码,理由是:</p>
<blockquote>
<p>Fork a second child and exit immediately to prevent zombies. This
causes the second child process to be orphaned, making the init
process responsible for its cleanup. And, since the first child is
a session leader without a controlling terminal, it's possible for
it to acquire one by opening a terminal in the future (System V-
based systems). This second fork guarantees that the child is no
longer a session leader, preventing the daemon from ever acquiring
a controlling terminal.</p>
</blockquote>
<p>因此,这是为了确保守护进程重新成为in it的父进程(以防启动守护进程的进程是长寿命的),并消除守护进程重新获取控制tty的任何机会。因此,如果这两种情况都不适用,那么一个叉子就足够了。”<a href="https://rads.stackoverflow.com/amzn/click/com/0201433079" rel="nofollow noreferrer">Unix Network Programming - Stevens</a>“对此有一个很好的部分。</p>