Hello, On 3/30/07, Gaurav Dhiman <gaurav.dhiman@xxxxxxxxxxx> wrote:
This seems quite strange to me as I had an understanding that two processes working on the same file will always have different file structure. Also, this would mean that a read by one of the processes on the file would affect the file position pointer in the other process? GD> Wherever a process forks another process all the "struct file" strucutres are shared between both processes unless and untill any one of those processes does not write to it at which time a seperate copy is created, this is also know as COW (Copy On Write). When a process is forked, no other "struct file" structure is created, rather the refference count for the "struct file" structures are incremented and there pointers are also saved in new process's file table (struct file_struct).
The CoW is completely unrelated to this. The struct file is a kernel space structure, not a user space one (like FILE). Having a file descriptor of an opened file does not mean that the contents of the file reside in the process (user space) memory, unless it is mmapped for example. Therefore, after fork, there remains one struct file for both processes even if it both are writing into it. BlackHole -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ