strace named the call and the file number, and /proc turns the number into a name. What remains is to find whom importer is waiting for.
flock(3, LOCK_EX — importer asks for a lock on the file with descriptor 3 and waits: another process holds it. This is how programs agree not to work on the same data at the same time.
/proc is a directory the kernel builds on the fly. Each process has its own directory in it, named by PID, and the files inside are what the kernel knows about the process right now:
| File | What it holds |
|---|---|
fd/ |
open files: descriptor number → path, socket or pipe |
status |
name, state, parent, owner, memory |
cmdline, cwd, environ |
command line, current directory, environment variables |
You read your own process without sudo, and the fd of a root process only with sudo. Ubuntu does not let strace attach without sudo even to your own process unless you started it from your shell — hence Operation not permitted.
Who holds a file is found from the other side — across all processes at once. That is what lsof does:
W after the descriptor number is a write lock. archiver holds it, and importer only waits.
archiver holds the lock on import.lock, and importer waits in flock. What happens to importer if archiver ends?
-
The kernel releases the lock when the holder closes the file or ends, and hands it straight to the waiting process. No restart is needed.
-
archiver's lock goes away, while the import.lock file stays in place. For importer this is exactly the moment it was waiting for.
When archiver ends, the kernel releases its lock and gives it to importer. importer loads the orders, writes imported.txt and exits — pgrep importer finds nothing any more.
Key points
-
sudo strace -p <PID>shows the call a process is waiting in; without sudo Ubuntu does not let you attach. -
/proc/<PID>/fdturns a descriptor number into a file, andstatusshows the process's state and owner. -
lsof <file>finds every process with that file;Win the FD column marks who holds the lock.