Site icon New Generation Enterprise Linux

Stop pgrep from lying to you about process arguments

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

Stop pgrep from lying to you about process arguments

🧩 The Challenge

Trying to hunt down a specific runaway script using pgrep often pulls up every instance of a shell instead of the one you actually care about. It drives me up the wall when I kill the wrong background worker because the process name matches too many things.

💡 The Fix

Use the full flag so the utility looks at the entire command line string rather than just the process name. This saves you from accidentally nuking your shell sessions when you’re just trying to bounce a specific worker.

pgrep -af "python3 /opt/worker/bin/processor.py"

⚙️ Why It Works

By default, this tool truncates the search to the task name stored in the process control block, which is limited to 15 characters on many systems. Adding the flags forces it to compare your query against the full command line argument list in the proc filesystem.

🚀 Pro-Tip: Pipe it straight into xargs kill if you really want to clear the deck fast.

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

0 0 votes
Article Rating
Exit mobile version