[comp.unix.wizards] unlinking open files

mick@auspyr.UUCP (06/18/87)

in article <7074@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) says:
>  * We use the despicable trick of unlinking an open temporary file.
>  * The alternatives are too painful.  

I've often wondered about this.

In the old days, I went through the pain of ensuring temp files
were deleted by cleanup routines called before each exit point
and upon catching nasty signals.

Then the above trick occurred to me (must've been one afternoon
after an especially heavy session at Ralph's)(AT&T joke)

I've thought long and hard about it and can't see any good reason
not to do this.  Obviously, during development it is nice to leave
temp files around etc etc....

But for real-world honest-to-god live applications, this seems like the
best solution to avoid leaving temp file clutter lying around
on poorly understood and administered Unix boxes.

Comments anyone?

-- 
----
Mick
	{sdencore,necntc,cbosgd,amdahl,ptsfa,dana}!aussjo!mick
	{styx,imagen,dlb,gould,sci,altnet}!auspyr!mick

barnett@vdsvax.steinmetz.UUCP (Bruce G Barnett) (06/19/87)

In article <6695@auspyr.UUCP> mick@auspyr.UUCP (Mick Andrew) writes:
>in article <7074@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) says:
>>  * We use the despicable trick of unlinking an open temporary file.
>>  * The alternatives are too painful.  
>
>I've often wondered about this.

>for real-world honest-to-god live applications, this seems like the
>best solution to avoid leaving temp file clutter lying around
>on poorly understood and administered Unix boxes.
>
>Comments anyone?
>
>Mick

One Question
	Would deleting open files cause problems on an
	NFS-based file system? 

One Comment
	I had a very unpleasant morning trying to re-organize
	a disk because it kept running out of room. I kept making
	more room, and the disk kept filling up. (we usually have a
	few users who create 20 Megabytes of new data each day)

	Finally I realized that the disk was filling up, but the
	du command wasn't showing it! Who was filling up the disk?

	Yes, someone had a process writing to a file. He deleted the
	file without killing the process, and forgot it was running.

	


-- 
Bruce G. Barnett  (barnett@ge-crd.ARPA) (barnett@steinmetz.UUCP)
-- 
"The difference between a Buddha and an ordinary man is that one knows
the difference and the other does not."

gwyn@brl-smoke.ARPA (Doug Gwyn ) (06/20/87)

In article <6695@auspyr.UUCP> mick@auspyr.UUCP (Mick Andrew) writes:
>Comments anyone?

The UNIX System V C library tmpfile() routine works like that.

ed@mtxinu.UUCP (Ed Gould) (06/20/87)

>One Question
>	Would deleting open files cause problems on an
>	NFS-based file system? 

Possibly.  This is one of the Unix file semantics that NFS does
not maintain.  However, since it is a common operation in the case
of temporary files, a client system that detects that a process
is unlinking a remote file that it has open will not actually
unlink the file.  Instead, it will rename the file and delay the
unlink until close time.

If some other system decides to unlink the file, then it will go
away and cause grief to the process that had it open.

-- 
Ed Gould                    mt Xinu, 2560 Ninth St., Berkeley, CA  94710  USA
{ucbvax,decvax}!mtxinu!ed   +1 415 644 0146

"A man of quality is not threatened by a woman of equality."

chris@nrcvax.UUCP (Chris Grevstad) (06/21/87)

mick@auspyr.UUCP (Mick Andrew) says:
>in article <7074@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) says:
>>  * We use the despicable trick of unlinking an open temporary file.
>>  * The alternatives are too painful.  
> ...
> ...
>But for real-world honest-to-god live applications, this seems like the
>best solution to avoid leaving temp file clutter lying around
>on poorly understood and administered Unix boxes.
>

Well, there are a couple of problems with this approach in real life.  First
is that it is not necessarily portable.  VMS refuses to unlink an open file.
I would make the assumption that there are other os's that feel the same way.

Another problem is when you later need to reference this unlinked file by its
name, rather than file handle (either fd or fp).  Tough to do when the file's
already gone.

VMS attempts to solve this problem by having an additional flag on open, to
indicate that this is indeed a temporary file and should be deleted on the
last close.  Unfortunately, it's functionally equivalent to, under UNIX,
unlinking an open file, thus removing the file name from the file system and
making it invisible for other applications that might need to see the file.

-- 
	Chris Grevstad
	{sdcsvax,hplabs}!sdcrdcf!psivax!nrcvax!chris
	ihnp4!nrcvax!chris

As Mad Max was wont to say: So-so-so-so-so-so-sorry about that, Chief!