Date: Sat, 26 Jan 2002 13:24:52 +1100 From: Edwin Groothuis <edwin@mavetju.org> To: Alex Ranaldi <axr7993@rit.edu> Cc: questions@freebsd.org Subject: Re: unlinking open files Message-ID: <20020126132452.M823@k7.mavetju.org> In-Reply-To: <0GQI0028YVW8VR@osfmail.rit.edu>; from axr7993@rit.edu on Fri, Jan 25, 2002 at 08:52:58PM -0500 References: <0GQI0028YVW8VR@osfmail.rit.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 25, 2002 at 08:52:58PM -0500, Alex Ranaldi wrote: > >From what I understand, if a file is open and deleted by the user (ie. an > apache log) problems will arise. For example, du and df will not display the > same value, as the kernel cannot free an open file. Even killing the process > using the file (in this case, Apache) will not help. Only a reboot seems to > solve the problem. It's not a bug, it's a feature. There is a difference between what the filesystem-part of the kernel (here after refered to as 'the kernel') knows and what is shows. If you open a file, the reference-count on that file will be increased by one. If you close it, it will be decreased by one. Say a normal file, unopened by anything, has a reference-count of 1. If you remove the file (unlink it), it gets removed from the directory index and the reference-count is decreased by one. If no other applications have opened this file, the reference-count is zero and there is nobody else using this file, the contents on disk can be removed now. If the reference-count would have been non-zero, which means somebody else was using this file, the contents on disk cannot be removed yet. After all, somebody else is using it! A good example of these situations are: - removing big files in /var/log, created by syslog - removable file-systems (i.e. CD's) If you remove a file from the directory index, it means you can regenerate a file with the same name. For what "ls" shows to you, it's the same file (not really true but close enough). For what the kernel knows, it's a different file. To see which applications are using a file you want to remove, install sysutils/lsof from the ports-collection: [~] edwin@k7>lsof -u edwin | grep access httpd-php 2778 edwin 19w VREG 116,131077 3585930 381204 /usr/home/www/log/access_log Edwin -- Edwin Groothuis | Personal website: http://www.MavEtJu.org edwin@mavetju.org | Interested in MUDs? Visit Fatal Dimensions: ------------------+ http://www.FatalDimensions.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020126132452.M823>