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

24 c unix linux fork

假设我打开一个文件open().那我是fork()我的节目.

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

我的意思是如果我在父亲那里写作,那么儿童的偏移量也会改变吗?

或者补偿是否会在fork()?之后独立?

Ign*_*ams 30

来自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)).
Run Code Online (Sandbox Code Playgroud)

  • 那...听起来像是一个内核bug. (2认同)

Mar*_*wis 5

它们确实共享相同的偏移量。