Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.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
C 创建守护进程时打开描述符_C_Linux_Daemon - Fatal编程技术网

C 创建守护进程时打开描述符

C 创建守护进程时打开描述符,c,linux,daemon,C,Linux,Daemon,R.Love的书《系统编程》中关于守护进程的一章说: 2. In the parent, call exit( ). 5. Close all file descriptors. 关于exit()调用的手册页显示: "The function _exit() terminates the calling process "immediately". Any open file descriptors belonging to the process are closed" 我们真的需要

R.Love的书《系统编程》中关于守护进程的一章说:

2. In the parent, call exit( ). 
5. Close all file descriptors. 
关于exit()调用的手册页显示:

"The function _exit() terminates the calling process "immediately". Any open file descriptors belonging to the process are closed" 

我们真的需要关闭子进程中的所有描述符吗,还是为了另一个安全?谢谢。

我相信是的,最好关闭所有FD,以防止父进程意外关闭时子进程成为孤立进程

你不是在同一个过程中做这两件事!您还应该写出从2到5的所有点,这样我们就可以告诉您,为什么它在两个不同的进程中。@zoska,是的,我知道,但在exit()中复制此操作,然后手动复制的原因是什么?这两个操作都发生在不同的进程中?孩子让父母打开fds,所以如果不需要,就应该关闭fds。没有重复,因为两者都是不同的进程。@zoska,谢谢,现在已经清楚了。孤立进程与打开的fds有什么关系?@zoska我假设他使用fork()函数创建新进程。