Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site sfmag.UUCP Path: utzoo!watmath!clyde!burl!ulysses!sfmag!mjs From: mjs@sfmag.UUCP (M.J.Shannon) Newsgroups: net.unix-wizards Subject: Re: How can unlinking be postponed? Message-ID: <683@sfmag.UUCP> Date: Sat, 7-Sep-85 11:02:48 EDT Article-I.D.: sfmag.683 Posted: Sat Sep 7 11:02:48 1985 Date-Received: Sun, 8-Sep-85 04:35:18 EDT References: <516@riccb.UUCP> Distribution: net Organization: AT&T Information Systems, Summit, NJ Lines: 28 > Perhaps I am misreading the manual, but I am under the impression that if > a process unlinks a file while any process has the same file open and that > is the last link to the file, then the actual removal of the file is post- > poned until the last process with the file open closes the file, either > explicitly or by exit or exec. Yet when I try experiments with one or > more background processes and then do ls's in the foreground, I find the > file disappears immediately after one process does its unlink()! What's > going on here? Does the directory entry disappear immediately but not > the i-node and its associated disk space? If that's so, shouldn't any > syscall except read return an error value since the process making that > call is under the reasonable impression that the file's still there when > it isn't? Is there no way for a file to be removed upon a process' exit? > -- > Roger Noe ihnp4!riccb!rjnoe Your surmise is correct: when the file is unlinked, its directory entry is removed. If the file is open, then the inode is retained until it is closed. Depending on what kind of file it is, the process that has it open can still read, write, lseek, fstat, ioctl, etc. That is, any system call that requires only a file descriptor, not a file name, may still be used successfully. Thus, your desire that the file will go away when the process exits is fulfilled! (Remember that an implicit close is done on any file descriptors a process has open at exit time.) -- Marty Shannon UUCP: ihnp4!attunix!mjs Phone: +1 (201) 522 6063 Disclaimer: I speak for no one.