How does `pgrep` command work?

0339

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

  1. Search by Process Name:
    To find the PID of a process named bash:

    pgrep bash
  2. 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
  3. 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.

0 Comments

no data
Be the first to share your comment!