What should you do if you find an active log file that is still being written to? Why can't you simply delete it?
Asked at
AI answer
First, find out which process writes to the file and how the application reopens logs. Deleting an active file usually removes only its name from the directory: the process continues writing to the open file descriptor, so disk space is not freed until the descriptor is closed. Meanwhile, the log is no longer accessible through its previous path, and its data may be lost when the process restarts.
Use log rotation: rename the file, create a new one, and ask the application to reopen the log (for example, with a signal or command). If reopening is not possible, copytruncate may be a temporary option, but copying can result in lost or duplicated entries. On Linux, you can find a process holding a deleted file, for example, with lsof +L1.
Also asked at RWB
- Why did you decide to change jobs / leave your current company?
- What is the key difference between TCP and UDP?
- What is the difference between git merge and git rebase? When should each approach be used?
- What is an inode in Linux?
- Which command is used to determine the route of a packet from your device to the target host?
Similar questions
- You found open, deleted files using lsof. What would you do with them next?
- A 20 GB log file was deleted with rm, but the disk space wasn’t freed. Why did that happen?
- How would you diagnose a situation where disk space is running out?
- Does a closed file have an inode? What is the difference between an open and a closed file when it is deleted?
- What should you do about accumulated zombie processes? How can you get rid of them?