When to use pgrep
Use pgrep to locate processes by names and other attributes before inspecting or signalling them. Choose exact-name matching or full-command matching deliberately; a broad pattern can select unrelated processes.
Syntax
pgrep [OPTIONS] TEMPLATESquare brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Find processes nginx
pgrep -a -x nginxExact-name nginx matches are displayed with their command lines.
View your shells
pgrep -a -u "$USER" bashMatching bash processes are restricted to the current user's account.
Search in full command line
pgrep -af 'python.*worker'A regular expression is matched against full command lines, which is broader than executable-name matching.
Notes and limitations
- By default, the pattern is a regular expression for the process name; -f uses the full command line.
- Code 1 means no match; the process may end immediately after the search.
Common questions and troubleshooting
Why are more processes matched than expected?
Full-command matching includes arguments and regular expressions. Narrow the account and pattern and review the output before acting.
What does no output mean?
There may be no matches, or visibility can be limited. Check the exit status and permissions instead of treating an empty result as a complete system inventory.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man pgrep.