[Bash] ps & pgrep commands

Zhentiw發表於2024-05-24

ps

The ps command is used to display information about running processes.
This command displays a snapshot of the current processes.

Common Options:

  • aux: Displays all processes in a detailed format.
  • -e: Shows all processes.
  • -f: Displays full-format listing.
# Display all running processes:
ps aux

Display all processes in full-format listing:
# ps -e

pgrep

The pgrep command searches for processes based on name and other attributes.

pgrep process_name

This command returns the process IDs of all processes with the given name.

# Find the process ID of a process named
$ pgrep postgres

473
592
593
594
595
596
597

# Find the process IDs and names of a process named bash:
$ pgrep -l postgres

473 postgres
592 postgres
593 postgres
594 postgres
595 postgres
596 postgres
597 postgres

# Find the process IDs of processes for a specific user:
$ pgrep -u username

相關文章