Linux Terminal Command: pgrep
The pgrep command is an essential tool in Process & Job Control. In this tutorial, we will explore what pgrep does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The pgrep command searches active system processes and lists the PIDs matching the search criteria.
Common Options & Syntax
pgrep [options] [arguments]
Here are the most common flags used with pgrep:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
pgrep sshd
What it does: Prints the process IDs of all running SSH daemons.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
pgrep -l -u root,www-data -f gunicorn
What it does: Lists both the PID and process name (-l) of all Gunicorn processes running under ‘root’ or ‘www-data’ users.
⚙️ Warning & Common Pitfalls
[!WARNING] By default,
pgreponly matches the first 15 characters of process names. Use the-fflag to match against the full command line path.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: