[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Files



On Wed, Dec 06, 2000 at 09:26:08AM +0530, Ramesh.S wrote:
> here in the above code after fork a seperate copy of the saem memory
> is inherited from the parent process. therefore every process will
> have its own resource copy. to be more clear...

A lot of answers become clear if you understand the meaning of a "file".
In UNIX, there are three distinct concepts:

1. file descriptor 
2. file table
3. body of the file

(1) is just a opaque handle. It's meaning is process specific.
(2) is normally not shared. But will be shared if you create a new process
    using clone and CLONE_FD false.
(3) is globally shared. This is enforced by a data structure called the
    vnode cache. Whether you do mmap/write or whatever operation to 
    read/write the file, at any point in time, the operating system returns
    the same answer to everyone who asks the question "what is the value
    of byte 2034 in file foo".

Note that sharing could be prevented using various flags at open(2) time
or mmap(2) time. Of course, you can serialize access to files using 
file locking APIs.

	-Arun