Re: Open files not shared with the child process ?

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

 





On 12/25/05, Rajaram Suryanarayanan <rajaram_linux@xxxxxxxxx> wrote:
Hi,
 

Here CLONE_FILES is not passed. i.e open file objects are not shared with the new process (child)...? But I have studied that when a process forks a child process, the files open by the parent will be shared with the new child process. And the reference count will also be incremented by 1.
 
Can anybody pls explain this..?

well .. when you call fork, the process descriptor of the calling process will be duplicated, then the new copy will be given to the child process control.
you can see that if a process has already opened 4 files there will be 7 files in the process file table (stdin, stdout, stderr, 4files then the new duplicated copy generated by fork will have the same entries in it's file table .. but from this moment and on .. each process (the parent and the child) will work on it's own copy .. and after this point, if the parent process opened a file nothing will be affected in the child process descriptor, and vice verse
here you can find the difference between clone and fork .. when a process clones a thread using clone then the new process descriptor (actually it's called "task" in Linux) will point it's resources like the file table to the parent process .. it won't copy it, it'll point to it instead .. and this is the reason why the process and the cloned task will still be able to share opened files (and any other cloned resource) till the end

hope it helps
MHD.Tayseer


[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