正在文件描述符共享fork()的ING什么时候? [英] Are file descriptors shared when fork()ing?

查看:133
本文介绍了正在文件描述符共享fork()的ING什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我打开与文件打开()。然后我叉()我的程序。

威尔的父亲和孩子现在共享的文件描述符相同的偏移?

我meanm如果我做我的父亲写,偏移将在孩子被改变呢?

或将偏移独立后叉()


解决方案

叉(2)


  *子继承打开文件描述符的父母的一套副本
     器。在子每个文件描述符是指在同一开
     文件描述(请参阅open(2))与相应的文件描述符
     在父。这意味着,两个描述符共享打开文件
     状态标志,当前文件偏移和信号驱动的I / O属性
     (见F_SETOWN和F_SETSIG中的fcntl(2)的描述)。


Let's say I open a file with open(). Then I fork() my program.

Will father and child now share the same offset for the file descriptor?

I meanm if I do a write in my father, the offset will be changed in child too?

Or will the offsets be independent after the fork()?

解决方案

From 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)).

这篇关于正在文件描述符共享fork()的ING什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆