gnu linux update question

Patrick O'Callaghan pocallaghan at gmail.com
Tue Jun 28 16:41:21 UTC 2011


On Tue, 2011-06-28 at 10:21 -0600, Petrus de Calguarium wrote:
> Andrew Haley wrote:
> 
> > How could it be otherwise?
> 
> If a file has been deleted, the proper thing would be for the running process 
> to read the new copy into memory.

And how is the process supposed to know? As for as it's concerned, the
file still exists. In fact it *does* still exist. It's a fundamental
feature of all Unix systems that a file only disappears when all
references to it go away. This includes both directory entries ("links")
and in-process open file descriptors.

To reinforce this principle, there is no "delete file" operation in Unix
(and Linux). There is only "unlink". Actually recovering space from the
file is a mere administrative detail that the system handles when
there's no longer any way to access the file contents.

The upshot is that if a process has a file open, and that file is
replaced by a different one (using unlink and creat) then the process
will continue to use the old file and all its attributes. When the
process closes the file, or terminates, the reference disappears and the
system then recovers the space. Meanwhile, a new directory entry with
the same name is pointing at the new contents.

On other systems you often see messages such as "Windows cannot update
until the following processes have exited". That's because Windows uses
the (broken) DOS model which doesn't distinguish between the file and
references to it.

If I had to pick out a single feature to demonstrate the superiority of
the Unix style of system, this would be it.

poc



More information about the users mailing list