Detecting that log file has been deleted or truncated on POSIX systems?

后端 未结 5 1289
难免孤独
难免孤独 2021-01-13 22:11

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.

5条回答
  •  余生分开走
    2021-01-13 23:02

    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.

提交回复
热议问题