Cloning 'struct file'
Prabhu nath
gprabhunath at gmail.com
Thu Jan 27 00:33:46 EST 2011
By experiment, we can know that all the fields of struct file are copied to
the child.
Here is what it happens.
When fork() is executed,
* A new array of struct file is created for the child.
* All the entries of the fd array of the parent is copied into the new array
of the child.
* Now both the parent and the child point to the same struct file pointer
for every opened
file that has been opened before fork.
* f_count (file object's usage count) is incremented by 1, indicating that
there is one more
task that is using this particular file object. This comes handy when a
task invokes
close(), i.e. when close() function is invoked by any task, the kernel
just decrements this
reference count. When the reference count is 0, VFS, invokes the release()
function of
the driver associated with this file and frees the respective file object.
Hope this helps...
Regards,
Prabhu
On Wed, Jan 26, 2011 at 4:29 PM, Daniel Baluta <daniel.baluta at gmail.com>wrote:
> Hi all,
>
> We know that each file descriptor fd, has an associated 'struct file'. How
> is
> the 'struct file' copied/cloned at fork?
>
> Are all fields of 'struct file' inherited by child? I want to know if
> there is a function
> which takes a struct file* and creates a consistent copy/clone of it.
>
> thanks,
> Daniel.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110127/2d70ccc8/attachment.html
More information about the Kernelnewbies
mailing list