Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have experienced the following paradox many times, and I don't understand how it happens.

I open a big music/video file (say 100 MB), and when it starts playing, I delete it (permanently). In spite of this, the media player will be able to play the whole thing.
I guess it doesn't buffer the whole file at the beginning, because

  • memory usage by the process is only 15 MB
  • and that's not what media players do anyway.

So how does this happen?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

The exact details depend on your system, but the basic idea is that the underlying filesystem won't pull the rug out from under an open file. It deletes it from everywhere you can see it, but it won't actually clean up the blocks on disk (nor some representation of the directory structures that point to the file) until you close it.

On Unix systems this is common: most unix filesystems won't blow away an inode until the last open filehandle is closed.

On Windows, it seems that if the opening process specifies 'FILE_SHARE_DELETE' to the CreateFile call (which a well behaved program should do), then the filesystem driver processes the deletion, but the open files can still access it. Once the last open HANDLE to the file is closed, then the file is cleaned up by the file system driver.

share|improve this answer
    
But I use Windows... Wether I can delete it or not seems to depend on the file type. –  Dave Feb 11 '13 at 20:29
2  
@Dave - see my revision - Windows has a way that (well behaved) programs can cause this to work correctly. –  Michael Kohne Feb 11 '13 at 20:37
    
agreed, this is a side effect of thread/multi-process resource share. –  Frank Thomas Feb 11 '13 at 21:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.