file offset pointer accross fork() ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I know the file position is located in the file struct.
I know that during normal fork, copy_process copies these
structures and doesn't share them between father and son
(unless CLONE_FILES is used, like in threads).
still, in the following code, i get answers that explicitly
make me think that file pointer is shared, even accross normal
fork:

int fd = open("file",...);
int pid = fork();
if(pid)
{
        lseek(fd,0,SEEK_SET);
        write(fd,"bbbbb",..);
}
else
{
        lseek(fd,0,SEEK_SET);
        sleep(5);
        write(fd,"aaaaa",..);
}


instead of "aaaaa" (the son should overwrite his fathers writings)
i get "bbbbbaaaaa". that means that during the father's writing,
the son's file position advanced, too !

why is that ?
why does all the kernel books i have state otherwise ?
what don't i understand here ?


thanks
S.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux