unremovable files?

Guy Harris guy at rlgvax.UUCP
Tue Apr 10 09:19:41 AEST 1984


> The file is probably in use by you or someone else. If the
> file is listed as being open, unix won't
> allow it to be removed until the file is released. It is the same
> problem you run into when you try to remove or remake /bin/sh, /etc/getty,
> etc.

Actually, this isn't the case for open files - UNIX will happily let you
unlink open files; the directory entry referencing the file will go away,
but the file will remain until the last process using the file closes it.
If the file is a shared-text executable image, however, UNIX will not let
you remove the last link to it until the last process using that shared
text goes away.

The reason the latter step was taken, I am told, is that if the system
crashed after the directory entry was removed but before the last process
finished with it, it would leave an "orphaned" file which "fsck" would
complain about.  This problem also occurs, however, in the first case
(an open file), so it's not clear that the restriction on unlinking active
shared-text executables (which arrived in V7, and continued in USG UNIX)
is really useful.  Berkeley decided it wasn't useful, so 4.xBSD permits you
to remove the last link to the file, which makes it easier to remake
programs like "/bin/sh".  It does mean, however, that you have to remember
that any process currently using that executable image will continue to
use the old image - only processes invoking the new executable image will
get it (which may have been another reason for not permitting the last
link to be removed - but, then again, you could rename "/bin/sh" to
"/bin/OLDsh" and drop in a new "/bin/sh" anyway).  I also removed it recently
from our own UNIX port.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.unix.wizards mailing list