Messages in this thread | | | Date | Thu, 23 Sep 1999 15:38:12 -0700 | From | Deepak Saxena <> | Subject | Question about clone() implementation |
| |
According to the clone(2) man page, calling clone() with the CLONE_FILES flag disabled will allow the parent and child to access files indpentely of each other. Specifically, it states:
"Operations on file descriptors performed later by one of the parent or child processes do not affect the other."
I looked at the code for copy_files (kernel/fork.c) and when the flag is not set, a new structure files_struct is allocated(newf) and the pointers for the file descriptors are copied over to the new table. From this it would appear that even though the file descriptor table is different, the child process is still sharing the specific fd. This means that if the child does an lseek() on a file, f_pos will change in both the child and the parent.
So the question I have is whether this behavior is correct according to what the man page describes? Or is the man page description not in synch with the implementaion? Or is it that my understanding of an "operation performed on a file descriptor" is incorrect?
Also, when CLONE_FILES is set, the code does:
if(clone_flags & CLONE_FILES) { atomic_inc(&oldf->count); goto out; }
out: return error;
Shouldn't tsk->files be set to oldf (which is initially set to current->files)? Or am I confused about the behavior of clone()?
Thanks, Deepak
-- http://www.plexity.net - phone://602.790.0500 - ICQ://49882790 /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Linux Demo Day Project | They are the functional Gods http://www.linuxdemo.org | mapping their visions into your reality Ultimate LUG Resource Project | isomorphic forms hiding the truth http://www.linux.com/lug | a homogeneous sea of falsity - 3.18.98
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |