Re: Re: file offset pointer accross fork() ?

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

 



Hi...

So would you all agree with the next summary then ?

this is the code which is responsible for copying the file structs:

     for (i = open_files; i != 0; i--) {
                 struct file *f = *old_fds++;
                 if (f) {
                         get_file(f);
                 } else {
                         /*
                          * The fd may be claimed in the fd bitmap but not yet
                          * instantiated in the files array if a sibling thread
                          * is partway through open().  So make sure that this
                          * fd is available to the new process.
                          */
                         FD_CLR(open_files - i, newf->open_fds);
                 }
                 *new_fds++ = f;
         }

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.

Right ?

On 9/30/05, Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:
> Hello...
>
> > I can't really agree with you.
> > lemme quote:
> >
> > asmlinkage int sys_fork(struct pt_regs regs)
> > {
> >          return do_fork(SIGCHLD, regs.esp, &regs, 0, NULL, NULL);
> > }
> >
> > fork uses SIGCHLD. only.
>
> Pfff, you are correct....so sorry for the wrong information. OK, I have
> done better research on 2.4.20 codes ( I assume it is still valid for
> 2.6.x/2.6.x.x), when doing fork(), somewhere on the call chain you will
> call copy_files() (located on kernel/fork.c). Please study the function
> for complete informations.
>
> From what I see at a glance, since sys_fork() doesn't use CLONE_FILES,
> it will copy the latest information about all open files currently
> accessed by the parent. In the other hand, when calling clone with
> CLONE_FILES, it is simply incrementing the counter:
>
> if (clone_flags & CLONE_FILES) {
>                atomic_inc(&oldf->count);
>                goto out;
>        }
>
> So, in short, fork() copy files_struct information, while
> clone(CLONE_FILES) simply take a note that more process share the
> structure.
>
> > threads use CLONE_FS (which has nothing to do with open files.
> > it is the file system struct which is current working directory, etc)
> > and CLONE_FILES (which is open files).
>
> yes, you are correct about it. Pardon me on my lack of knowledge in
> filesystem area...There is also an option for sharing namespace...but
> that is another story ;)
>
> regards
>
> Mulyadi
>
>

--
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