Interview Prep/Linux/Filesystem Hierarchy, Inodes & Links

What happens when you delete a file that a process still has open?

IntermediateConceptFilesystem Hierarchy, Inodes & Links
Answer

rm removes the directory entry (link count drops to 0), but the inode and blocks stay allocated until the last file descriptor is closed. df keeps showing the space as used while du does not.

sudo lsof +L1                  # open files with link count 0
: > /proc/<pid>/fd/<fd>        # truncate without restarting

Restarting or signalling the process to reopen its logs releases the space.

All Linux questions Roadmap: Linux

More on Filesystem Hierarchy, Inodes & Links