OS / THE GHOST FILE
FILE SYSTEM MANAGEMENT · UNIX
01 / 12 — AN OPERATING SYSTEMS EXPERIMENT

THE
GHOSTFILE.

Deleted. Invisible. Still alive.

File lifetime management through i-nodes, file descriptors and reference tracking.
01 / 07 — CREATE

Meet the original file.

ORIGINAL FILE · INODE A
Hard links
0
Open references*
A name is attached to the file.
FILE SYSTEM / LIVE MODEL
● ALLOCATED
Animated model of file lifetimeThe filename and the shell's descriptor refer to an underlying file object. ACCESS ROUTESFILE OBJECTS DIRECTORY ENTRYghost.txtname → inode A SHELL PROCESSFD 3: closedno open reference INODE A · ORIGINALORIGINAL FILEdata remains allocated A and B are illustrative inode identities.
SIMULATED SHELLSCROLL TO RUN
$
09 / 12 — TECHNICAL REVEAL

Inside
the kernel.

A pathname is resolved once when a file is opened. Reading through a descriptor uses the existing open file description, not a fresh lookup of the old name.

open()unlink()read()close()
USER SPACEKERNEL · PER PROCESSKERNEL · OPEN DESCRIPTIONFILESYSTEM NAMESPACESHARED UNDERLYING OBJECTShell / applicationFD table · 3Flags + file offsetghost.txtFile object / inode AFile datasystem callsOpen file descriptionDirectory entry → inode AMetadata · link count · block mappingKERNEL BOUNDARY
10 / 12 — RESOURCE MANAGEMENT

When can
the file die?

The last name can disappear before the last open reference. The OS must retain the original file until both are gone.

*The demo counts one persistent shell reference. Temporary references during reads are omitted. Other kernel references, mappings and snapshots can complicate real storage reclamation.

// Simplified lifecycle rule
if (links == 0
  && refs == 0) {
  reclaim(file);
}
Reclamation ≠ secure erasure.
11 / 12 — REAL-WORLD RELEVANCE

Change the file.
Don't interrupt the reader.

A same-filesystem atomic rename can replace a published pathname with a new file while existing readers keep their old open references.

EXISTING READER

Version A

Continues reading the original open file object.

NEW READER

Version B

Resolves the same pathname to the newly published file.

Another consequence: deleted but open files can still consume storage until their remaining references are released.

12 / 12 — CASE CLOSED

A filename
is not the file.

On UNIX, a file can outlive its last name. Its storage becomes reclaimable only when the remaining references are released.

Thank you.Questions & discussion
FINAL OBJECT STATEHARD LINKS0OPEN REFERENCES0INODE ASTORAGE RECLAIMABLE

Verify it in a real terminal

The webpage simulates UNIX file-system operations. Browsers cannot run these shell commands directly without an external backend. Use this isolated experiment on macOS or Linux to verify the behavior. It creates and removes only its own temporary files.

(
  tmp=$(mktemp -d) || exit 1
  cd "$tmp" || exit 1
  printf 'ORIGINAL FILE\n' > ghost.txt
  ls -i ghost.txt
  exec 3<ghost.txt
  rm ghost.txt
  cat ghost.txt
  printf 'NEW FILE\n' > ghost.txt
  ls -i ghost.txt
  cat ghost.txt
  cat <&3
  exec 3<&-
  rm ghost.txt
  cd / && rmdir "$tmp"
)

Expected: the old pathname fails after removal; the new pathname prints NEW FILE, while FD 3 prints ORIGINAL FILE. Actual inode numbers will differ from the symbolic A/B labels.

Course & technical references

Operating Systems — Xiping Liu, NJUPT. Chapter 4: file operations, directory operations (link/unlink), i-nodes and shared files. Chapter 1: system calls. Chapter 2: process implementation and open files.

open(2) — open file descriptions and descriptors
unlink(2) — removal of a name and lifetime
rename(2) — atomic replacement
close(2) — closing a descriptor

Visual model: illustrative UNIX-style semantics, not a trace of a running kernel. Reclamation is not secure erasure.