A running application can keep writing to a log after its pathname has been removed. On Linux, a process's open files show which paths it has open for writing and which sockets and pipes it holds before you restart it or investigate a permission problem.
Each process has its own file descriptors, the numbered handles it uses for open resources. A service can have several processes, so its main process and its workers may hold different files and sockets.
An open-file listing shows what the process holds at the time of the lookup. After a restart, the process can have a new PID and a different set of descriptors. The account running the lookup also determines how much of the list it can see.
Steps to check files opened by a process in Linux:
- Confirm the process identity using your PID in place of 363.
$ ps -p 363 \ -o pid,comm,user:32 PID COMMAND USER 363 python3 appIf USER ends in +, increase 32 to see the full account name. If the row is missing or the owner or command differs, find the current PID. If you have a systemd service name, its status lists the main PID.
Related: How to check Linux service status - List the open files using the same PID in place of 363.
$ lsof -nP -p 363 FD TYPE NAME ##### snipped ##### 15w REG /tmp/app.log 16w REG /tmp/old.log (deleted) 17u IPv4 127.0.0.1:56017 (LISTEN) 18r FIFO pipe 19w FIFO pipe 20u a_inode [eventpoll]Only FD, TYPE and NAME are shown, with long names wrapped. Numbered FD entries use r for read, w for write and u for read/write. The TYPE column identifies regular files (REG), sockets (IPv4 here), pipes (FIFO) and anonymous handles (a_inode). In NAME, (deleted) marks an unlinked file still open.
Related: How to check deleted files still open in LinuxA usable row has a numbered FD and readable TYPE and NAME fields. If NAME shows Permission denied beside a numbered FD or NOFD, retry with sudo if authorized. No rows or No such file or directory can mean the process exited.
If lsof is unavailable, use that same PID in ls -l /proc/363/fd to list numbered links and their targets. An unreadable link target leaves the resource unidentified. A pathname alone leaves the target's file type undetermined.