Wednesday 5 December 2018

unix - When does rm remove open files?


Particularly, I want to know what happens when I rm an open file and don't explicitly kill the process holding the file descriptor to that file. Will the file be removed when the system is shut down?



Answer



Basically, yes - whenever the process holding it open dies. Nothing "magical" happens at that point. Just like a directory entry for the file is a "hard link" to the blocks that contain that file's data, so is an open file handle. If there is no directory entry and no open file handle then the blocks are free to be reused. This means that even if you don't do a clean shutdown (eg. yank the power cord) the file will still be deleted - it was "deleted" when you ran rm, only its blocks were not immediately available for reuse.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...