Stop lsof from making you wait an eternity to find who locked that file

Process & Resource Monitoring (Top/Htop/Ps/Systemd)

Stop lsof from making you wait an eternity to find who locked that file

🧩 The Challenge

You’ve got a production script that is dead in the water because some ghost process has a handle on a log file, and running a simple lsof just hangs for minutes while it crawls through your mount points. I’ve wasted so much time staring at a blinking cursor while production is down just because I needed to know which process was holding a file lock.

💡 The Fix

Use the -d flag to filter specifically for file descriptors or stick to just checking the file path without letting lsof walk the entire mounted filesystem tree. It makes the search near-instant.

lsof +D /var/log/myapp/ -c myprocessname

⚙️ Why It Works

Adding the +D flag tells the utility to restrict its search to a specific directory tree rather than querying the entire system’s open file list. By combining that with a command filter, you stop the tool from drowning in noise.

🚀 Pro-Tip: Alias this command as findlock so you don’t have to remember the flags when the pager is going off at 3 AM.

Linux Tips & Tricks | © ngelinux.com | 8/6/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted