Suppose a lengthy process is written to a log file. Assume that the log file remains open indefinitely. Suppose a careless system administrator deletes this log file. Can a program detect that this happened?
Is it possible to assume that fstat() will report the number of null references for the remote file?
Truncation, it seems to me, is a little more complicated. This partly depends on whether the file descriptor is in O_APPEND mode. If the log file does not work with O_APPEND , then the current position of the log entry of the program log descriptor does not change, and truncation removes the leading bytes, but the program continues to write at the "end", leaving a space from phantom zero bytes (they are considered zeros, but do not necessarily take up space by drive).
If the program works with O_APPEND , then it will write at the end of the file how it exists. The only way to observe truncation is to note that the file position is not where the program was expecting, which in turn means tracking this position explicitly.
In general, truncation as removal does not bother me as much, but any thoughts would be welcome.
source share