假设我用open()
打开一个文件,然后fork()
我的程序。
父进程和子进程现在会共享文件描述符的相同偏移吗?
我的意思是如果我在父进程中进行写操作,那么在子进程中偏移量也会改变吗?
还是说fork()
后偏移量将是独立的?
来自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()
会导致子进程继承一些父进程的结构。如果没有父子关系,那么... - Ignacio Vazquez-Abrams