CS FundamentalsHardGATE CS (PYQ pattern)

On a Unix file system with an empty directory /tmp/x (call it X), these commands run: mkdir X/a; mkdir X/a/b; mkdir X/a/c; touch X/a/f; ln X/a/f X/a/b/g; ln -s X/a/f X/h; rm X/a/f; rmdir X/a/c. Afterwards, what is the link count of directory X/a, what is the link count of the inode that X/a/b/g names, and what does opening X/h do?

  1. A. 4; 1; it fails because the symbolic link dangles
  2. B. 3; 2; it opens the file through g
  3. C. 2; 1; it opens the file because the inode still exists
  4. D. 3; 1; it fails because the symbolic link dangles

Correct answer: D. 3; 1; it fails because the symbolic link dangles

A directory's link count = its entry in the parent + its own '.' + one '..' per subdirectory: X/a has b left after c is removed, so 3 (4 before rmdir). The file had links f and g; rm removes f, leaving 1, so the data survives through g. The symbolic link stores the path X/a/f, which no longer exists, so it dangles even though the inode lives on.

More Operating Systems questions

Exams that ask this topic