Watch exactly which files your app is locking right now

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

Watch exactly which files your app is locking right now

🧩 The Challenge

You have a service that’s hanging or throwing permission errors, but logs aren’t telling you which file handle is causing the deadlock. I’ve spent way too many nights guessing why a database process wouldn’t release a WAL file.

💡 The Fix

Use lsof to filter for the specific process ID so you can see every open file descriptor at a glance. It saves you from digging through blind diagnostic output.

lsof -p $(pgrep -u username process_name)

⚙️ Why It Works

By feeding the output of pgrep directly into the lsof command, you target only the process that’s actually causing your headache. It cuts out the noise of every other task running on the server.

🚀 Pro-Tip: Add a +D /path/to/dir to the command if you only care about locks happening in a specific directory.

Linux Tips & Tricks | © ngelinux.com | 11/2/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted