The pgrep command is used to search for processes based on their name and other attributes. It returns the process IDs (PIDs) of the matching processes. Here's how it works:
Basic Syntax
pgrep [options] pattern
Example Usage
-
Search by Process Name:
To find the PID of a process namedbash:pgrep bash -
Search with Options:
-u: Search for processes owned by a specific user.pgrep -u username-l: List the process names along with their PIDs.pgrep -l bash
-
Regular Expressions:
You can use regular expressions to match process names.pgrep -f 'python.*script.py'
Output
The command outputs the PIDs of the processes that match the specified pattern. If no processes match, it returns no output.
Summary
pgrep is a powerful tool for quickly finding process IDs based on specific criteria, making it useful for process management in the terminal.
