How to safely maintain a status file

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jul 14 03:53:42 CEST 2012


On Fri, 13 Jul 2012 15:15:13 -0500, Chris Gonnerman wrote:

> On 07/13/2012 12:59 PM, Prasad, Ramit wrote:
>> I lean slightly towards the POSIX handling with the addition that any
>> additional write should throw an error. You are now saving to a file
>> that will not exist the moment you close it and that is probably not
>> expected. Ramit
> But if I created, then deleted it while holding an open file descriptor,
> it is entirely likely that I intend to write to it. I'll admit, these
> days there are those in the Unix/Linux community that consider using an
> anonymous file a bad idea; I'm just not one of them.

A badly-behaved application can write oodles and oodles of data to an 
unlinked file, which has the result of temporarily using up disk space 
that doesn't show up when you do an ls. For an inexperienced system 
administrator, this may appear mysterious.

The solution is to us lsof to identify the unlinked file, which gives you 
the process id of the application, which you can then kill. As soon as 
you do that, the space is freed up again.

Like all powerful tools, unlinked files can be abused. Underpowered tools 
can't be abused, but nor can they be used.


-- 
Steven



More information about the Python-list mailing list