From owner-freebsd-questions Fri Jan 25 18:25: 8 2002 Delivered-To: freebsd-questions@freebsd.org Received: from topaz.mdcc.cx (topaz.mdcc.cx [212.204.230.141]) by hub.freebsd.org (Postfix) with ESMTP id 1A93F37B400 for ; Fri, 25 Jan 2002 18:25:05 -0800 (PST) Received: from k7.mavetju.org (topaz.mdcc.cx [212.204.230.141]) by topaz.mdcc.cx (Postfix) with ESMTP id 4274D2B82F; Sat, 26 Jan 2002 03:25:00 +0100 (CET) Received: by k7.mavetju.org (Postfix, from userid 1001) id 487FD151; Sat, 26 Jan 2002 13:24:52 +1100 (EST) Date: Sat, 26 Jan 2002 13:24:52 +1100 From: Edwin Groothuis To: Alex Ranaldi Cc: questions@freebsd.org Subject: Re: unlinking open files Message-ID: <20020126132452.M823@k7.mavetju.org> References: <0GQI0028YVW8VR@osfmail.rit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <0GQI0028YVW8VR@osfmail.rit.edu>; from axr7993@rit.edu on Fri, Jan 25, 2002 at 08:52:58PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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