gpt4 book ai didi

c - 创建守护进程时离开调用 setsid() 有什么影响?

转载 作者:可可西里 更新时间:2023-11-01 11:46:33 27 4
gpt4 key购买 nike

守护进程时不调用 setsid() 有什么危险?

最佳答案

When a user logs out from a session, all processes associated with that session are killed. For processes that are daemons you do not want this to happen. The solution is to call setsid. Provided that the daemon is not already a process group leader (which it will not be following the fork performed above), this will:

  1. start a new session, with the daemon as session leader and with no controlling terminal, and
  2. start a new process group, with the daemon as process group leader.

来自 here

所以基本上,如果你不给它一个新的 session ID,它可能会被无意中杀死。

关于c - 创建守护进程时离开调用 setsid() 有什么影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16638616/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com