Site icon New Generation Enterprise Linux

Quit manually tracking process tree deaths

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

Quit manually tracking process tree deaths

🧩 The Challenge

Dealing with a daemon that keeps spawning child processes like rabbits only to have them drop dead before I can run a quick ps to see what they were doing is pure misery. I’ve spent way too long staring at a blank shell waiting for the next crash.

💡 The Fix

Use pgrep with the monitoring flag so the terminal waits and prints the PIDs the second they pop into existence. It saves you from having to hit the up-arrow key until your finger cramps.

pgrep -f my_problematic_script -w

⚙️ Why It Works

Adding the -w flag turns the tool into a listener that blocks until it sees a match, capturing those ephemeral PIDs that vanish in a millisecond. It effectively turns a static lookup into a real-time event trap.

🚀 Pro-Tip: Pipe it into xargs to automatically attach a debugger the second a bad process starts.

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

0 0 votes
Article Rating
Exit mobile version