好问题,这个坑我也是Google了之后才搞清楚。
* 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)).
具体来说,先open()后fork()的情况下,父子进程不共享用户态的IO buffer,但是共享内核态的文件状态,其中包括offset。
【 在 paramita555 的大作中提到: 】
:
: 大佬,麻烦再解释一下,为啥子进程的exit修改了它自己的offset,我理解父进程中FILE的offset应当不变啊,它又没有重新打开这个文件,为什么还需要手动ftell/fseek呢?
--
FROM 203.18.50.*