参考
https://www.man7.org/linux/man-pages/man7/daemon.7.html
https://www.man7.org/linux/man-pages/man3/daemon.3.html
说明
将当前进程运行到后台,脱离当前session、shell。
#include <unistd.h>
int daemon(int nochdir, int noclose);
需要注意的问题
调用者直接退出exit_group(0)
从 daemon-7里可以看到,这个方法会将之前的线程直接exit_group(0) 。这样在判断返回值时其实不是真正的线程的状态。
1035338 08:40:51.880893 exit_group(0) = ?
- Call exit() in the first child, so that only the second child (the actual daemon process) stays around. This ensures that the daemon process is re-parented to init/PID 1, as all daemons should be.