c - fork() 时是否共享文件描述符?

标签 c linux unix fork

假设我用 open() 打开一个文件。然后我 fork() 我的程序。

父亲和 child 现在会共享相同的文件描述符偏移量吗?

我的意思是,如果我在父亲中写入,子代中的偏移量也会改变吗?

或者在 fork() 之后偏移量是独立的吗?

最佳答案

来自 fork(2):

  *  The child inherits copies of the parent’s set of open file  descrip-
     tors.   Each  file  descriptor  in the child refers to the same open
     file description (see open(2)) as the corresponding file  descriptor
     in  the parent.  This means that the two descriptors share open file
     status flags, current file offset, and signal-driven I/O  attributes
     (see the description of F_SETOWN and F_SETSIG in fcntl(2)).

关于c - fork() 时是否共享文件描述符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4277289/

相关文章:

unix - 我应该学习什么Unix文本编辑器?

c - 终止进程时是否可以删除文件?

c - 移位不适用于变量声明赋值单行

c++ - 使用 c++ 和 x86 和 x64 架构访问处理器中断

linux - 在 linux box 上运行 nightwatch.js 测试?

linux - 在 *nix 环境中,我如何将列组合在一起?

c - fprintf 后文件指针设置为 NULL

c - 接收/接收的最大镜头数是多少

c - 我在第二次输入语言时收到错误

c++ - 段错误和指针问题