[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: file offset pointer accross fork() ?
Thanks Florin !!
On 9/30/05, Florin Malita <fmalita@xxxxxxxxx> wrote:
> On Fri, 30 Sep 2005 21:17:26 +0200
> Sebastian Skar <sebastianskar@xxxxxxxxx> wrote:
> > we can see that the pointers are shallow copied (not 'copy constructed'...),
> > so basically even across fork the same file position is relevant for
> > both father and child.
>
> btw, this isn't linux specific - it's covered by POSIX and
> documented in glibc:
>
> http://www.jaluna.com/doc/c5/html/ManPages/hman2posix/fork.2posix.html
>
> "The child process has its own copy of the parent's descriptors. These
> descriptors reference the same underlying objects, so that, for
> instance, file pointers in file objects are shared between the child
> and the parent, so that an lseek(2POSIX) on a descriptor in the child
> process can affect a subsequent read(2POSIX) or write(2POSIX) by the
> parent."
>
> http://www.gnu.org/software/libc/manual/html_node/File-Position-Primitive.html
>
> "You can have multiple descriptors for the same file if you open the
> file more than once, or if you duplicate a descriptor with dup.
> Descriptors that come from separate calls to open have independent file
> positions; using lseek on one descriptor has no effect on the other.
> [...]
> By contrast, descriptors made by duplication share a common file
> position with the original descriptor that was duplicated. Anything
> which alters the file position of one of the duplicates, including
> reading or writing data, affects all of them alike."
>
> Cheers,
> Florin
>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/