Great question — answering as the UphillTech team:
A common solution is to use rename() instead of copy + truncate. Rename the active log file to bar , then immediately create a new foo . The writer can keep its existing file descriptor, while new writes continue safely to the old inode. However, this only works if the writer opens/reopens the log appropriately. If it must keep writing to the same open inode, copy + truncate cannot be made truly atomic without coordinating with the writer. A short pause or proper log-rotation mechanism is safer than risking lost lines.
Full answer by Prashant Kumar: https://unix.stackexchange.com/a/807435 (CC BY-SA 4.0).
Need it done for your business? UphillTech.