代码之家  ›  专栏  ›  技术社区  ›  anon

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

  •  24
  • anon  · 技术社区  · 14 年前

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

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

    我是说,如果我在我父亲的作品中,偏移量也会在child中改变?

    或者在 叉() ?

    2 回复  |  直到 6 年前
        1
  •  30
  •   Ignacio Vazquez-Abrams    14 年前

    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)).
    
        2
  •  3
  •   Martin v. Löwis    14 年前

    它们共享相同的偏移量。