假设我使用打开文件open()。然后我fork()我的程序。
open()
fork()
现在,父亲和孩子会为文件描述符共享相同的偏移量吗?
我的意思是,如果我在父亲那里写书,那么偏移量也会在孩子身上改变吗?
还是在fork()?之后偏移是独立的?
来自fork(2):
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)).