By experiment, we can know that all the fields of struct file are copied to the child. <br>Here is what it happens. <br>When fork() is executed, <br>* A new array of struct file is created for the child. <br>* All the entries of the fd array of the parent is copied into the new array of the child. <br>
* Now both the parent and the child point to the same struct file pointer for every opened <br>  file that has been opened before fork. <br>* f_count (file object&#39;s usage count) is incremented by 1, indicating that there is one more<br>
  task that is using this particular file object. This comes handy when a task invokes  <br>  close(), i.e. when close() function is invoked by any task, the kernel just decrements this<br>  reference count. When the reference count is 0, VFS, invokes the release() function of <br>
  the driver associated with this file and frees the respective file object. <br><br>Hope this helps...<br><br>Regards,<br>Prabhu<br><br><br><br><div class="gmail_quote">On Wed, Jan 26, 2011 at 4:29 PM, Daniel Baluta <span dir="ltr">&lt;<a href="mailto:daniel.baluta@gmail.com">daniel.baluta@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,<br>
<br>
We know that each file descriptor fd, has an associated &#39;struct file&#39;. How is<br>
the &#39;struct file&#39; copied/cloned at fork?<br>
<br>
Are all fields of &#39;struct file&#39; inherited by child? I want to know if<br>
there is a function<br>
which takes a struct file* and creates a consistent copy/clone of it.<br>
<br>
thanks,<br>
Daniel.<br>
<br>
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</blockquote></div><br>