Bash Wiki
Posts (Latest 30 updated) :
Read all
Contents:
  1. [Linux] Bash pidof Uso: Get process IDs of running programs
    1. Overview
    2. Usage
    3. Common Options
    4. Common Examples
    5. Tips

[Linux] Bash pidof Uso: Get process IDs of running programs

Overview

The pidof command in Bash is used to find the process IDs (PIDs) of running programs. It is particularly useful for identifying the PIDs associated with a specific executable, allowing users to manage processes effectively.

Usage

The basic syntax of the pidof command is as follows:

pidof [options] [arguments]

Common Options

  • -o, --exclude: Exclude specified PIDs from the output.
  • -s, --single: Return only a single PID for the specified program.
  • -q, --quiet: Suppress output; return exit status only.

Common Examples

Here are some practical examples of using the pidof command:

  1. Get the PID of a specific program:
    pidof firefox
    
  2. Get PIDs of multiple programs:
    pidof firefox chrome
    
  3. Exclude a specific PID from the output:
    pidof -o 1234 firefox
    
  4. Get only a single PID of a program:
    pidof -s apache2
    
  5. Check if a program is running (quiet mode):
    pidof -q ssh
    

Tips

  • Use pidof in scripts to dynamically manage processes based on their PIDs.
  • Combine pidof with other commands like kill to terminate processes easily. For example:
    kill $(pidof firefox)
    
  • Remember that pidof returns nothing if the specified program is not running, which can be useful for conditional checks in scripts.