Suppose a long-running process writes to a log file. Suppose that log file is kept open indefinitely. Suppose that a careless system administrator deletes that log file.
Checking that fstat()
returns a link count of zero would fail if the file was hard linked or renamed. I would probably instead periodically compare stat()
's inode number against fstat()
's.
I'm not sure about truncation.
tail -F
checks for deletion and maybe truncation, so I'd check its source to see how it implements it.