Reputation: 79
I'm working on ed (yes, the editor) source code. The program uses a scratch file, opened with tmpfile, as a buffer. But, whenever I run the program, lsof always report the temporary file as deleted! (and in fact it's not there). Why?
Upvotes: 2
Views: 85
Reputation: 423
Because a file can exist on disk without having a filename associated with it, many programs will open a file and then promptly unlink it. The file contents can continue to be modified & read by open file-handles on the file, and won't actually be removed from the disk until all open file handles are closed.
(this is for *nix/POSIX platforms AFAICT; Windows handles files differently, preventing unlinking if an program has the file-handle still open, and thus reboots are often needed for upgrades to force those open file-handles to be closed so file contents can be replaced)
Upvotes: 0