I'm wriiting a logger on linux.
the logger open a file on init.
and write to that file descriptor as the program run.
if the log file will be deleted after the file descriptor was created,
no exception/error will be detected .
i have tried:
i have google this and find this post .
so i understand now that even if the file was deleted by using rm. it is still exist, it was simply unlinked.
what is the best way to handele this?
1. this is a log application so performance is an issue , i don't want to use stat() on every write
2. i don't care if some of the line in the log files will be missing at the start
3. the user is allowed to delete the log file, to start fresh .the logger should reopen the file.
Files are 'unlinked' by
A file can have many names. When it has no names left, and nobody has it open, then it is reclaimed by the file system and the space it occupies can be reused.
Linux has an API for 'watching' files called
inotify, but this is inviting complexity and race conditions.
So the bigger question is, who else is deleting this file when it is run, and why? Convince them not to!