Dash Wiki
Posts (Latest 10 updated) :
Read all
Contents:
  1. [English] Debian Almquist Shell (dash) pgrep Usage: Find process IDs by name
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[English] Debian Almquist Shell (dash) pgrep Usage: Find process IDs by name

Overview

The pgrep command in the Debian Almquist Shell (dash) is used to search for processes currently running on the system based on their names or other attributes. It returns the process IDs (PIDs) of the matching processes, making it a useful tool for managing and monitoring system processes.

Usage

The basic syntax of the pgrep command is as follows:

pgrep [options] [arguments]

Common Options

  • -u USER: Search for processes owned by the specified user.
  • -f: Match against the full command line instead of just the process name.
  • -n: Only return the newest (most recently started) process.
  • -o: Only return the oldest (least recently started) process.
  • -l: List the process names along with their PIDs.

Common Examples

Here are some practical examples of using the pgrep command:

  1. Find the PID of a specific process by name:
    pgrep bash
    
  2. Find PIDs of processes owned by a specific user:
    pgrep -u username
    
  3. Match against the full command line:
    pgrep -f "python script.py"
    
  4. Get the newest instance of a process:
    pgrep -n ssh
    
  5. List PIDs along with process names:
    pgrep -l httpd
    

Tips

  • Use pgrep in combination with other commands like kill to terminate processes by their names.
  • For scripts, consider using pgrep with the -f option to ensure you are matching the correct command line.
  • When searching for processes, be mindful of case sensitivity; pgrep is case-sensitive by default. Use the -i option for case-insensitive matching.