Linux ps Command: Inspect Running Processes

ps shows a list of processes at the time of execution. It is used to check the PID, user, status, and command to investigate whether a particular service or task is actually running.

What is the ps command?

ps outputs a snapshot at a single point in time and then ends. If you want to see values that change in real time, use top or htop. The option notation includes both POSIX and BSD styles, so the meaning can differ depending on whether a hyphen is used.

Basic syntax

ps [options]

The installed implementation and options may vary depending on the distribution. Check the description for the current system with man ps.

Examples

Processes of the current terminal

When run without arguments, it usually only shows processes connected to the current terminal.

ps

System-wide processes

It provides a broad view of the user, PID, parent PID, and command.

ps -ef

Specifying fields of a specific PID

If you specify only the necessary columns, it is easier to read scripts and check results.

ps -p 1234 -o pid,ppid,user,stat,cmd

How to Read Process Columns

ps shows a snapshot of processes at the time of execution. By specifying columns, you can clearly distinguish PID (process ID), PPID (parent PID), status, and command name.

ps -o pid,ppid,stat,comm -p $$

Example output (numbers will vary each time you run it):

    PID    PPID STAT COMMAND
   4321    4100 Ss   bash

$$ is the PID of the current shell. The first letter of STAT indicates the state such as running or waiting, and the following letters indicate additional states. Since processes may terminate immediately after being queried, make sure to verify the PID and command again before executing a termination command.

Main Options and Format

Options/Format Description
-e Select the entire process.
-f Output in detailed format.
-p PID Select only the specified process ID.
-o column_list Specify the fields and order to be output.
aux View all user processes and resource information in BSD style.

Precautions when using

ps | grep name can include the grep process itself in the results. pgrep is convenient for searching PIDs by name. Since processes can be created and terminated quickly, make sure to check again that the PID is still the same task before sending a signal right after the output.

Frequently Asked Questions

What is the difference between ps and top?

ps prints a snapshot of the process list at the moment it is executed and then exits. top periodically refreshes the screen so you can observe changes over time.

Official Documentation

The exact behavior of options and implementation differences can be found in the official ps documentation.

More in This Category
Linux basename Command: Extract the Final Component of a Path

Linux basename Command: Extract the Final Component of a Path

Learn how to use the Linux basename command to remove directory prefixes and optional suffixes from path strings, with essential options, practical examples, output interpretation, and common troubleshooting tips.

How to Check the Linux Distribution, Version, Kernel, and Architecture

How to Check the Linux Distribution, Version, Kernel, and Architecture

Learn how to identify a Linux distribution and version with /etc/os-release, then check the running kernel and CPU architecture with hostnamectl and uname. The guide also covers scripts, legacy systems, containers, WSL, and chroot environments.

Linux passwd Command: Change a User Password

Linux passwd Command: Change a User Password

Learn how to change a User Password with the Linux passwd command, including practical examples, key options, and important precautions.

Linux command Command: Run Commands While Bypassing Aliases and Functions

Linux command Command: Run Commands While Bypassing Aliases and Functions

Learn how to use the Linux command command to check command availability and bypass shell aliases or functions, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux systemctl Command: Manage systemd Services

Linux systemctl Command: Manage systemd Services

Learn how to manage systemd Services with the Linux systemctl command, including practical examples, key options, and important precautions.

Linux nmap Command: Scan Authorized Hosts and Ports

Linux nmap Command: Scan Authorized Hosts and Ports

Learn how to scan Authorized Hosts and Ports with the Linux nmap command, including practical examples, key options, and important precautions.

Linux apropos Command: Search Commands by Description

Linux apropos Command: Search Commands by Description

Learn how to use the Linux apropos command to find relevant manual pages by searching description keywords, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux mv Command: Move and Rename Files and Directories

Linux mv Command: Move and Rename Files and Directories

Learn how to move and rename files or directories with Linux mv, avoid unwanted overwrites, clarify destination paths, and handle cross-filesystem moves.

Linux tmux Command: Detach and Reattach Terminal Sessions

Linux tmux Command: Detach and Reattach Terminal Sessions

Learn how to detach and Reattach Terminal Sessions with the Linux tmux command, including practical examples, key options, and important precautions.

Linux id Command: Show User and Group IDs

Linux id Command: Show User and Group IDs

Learn how to show User and Group IDs with the Linux id command, including practical examples, key options, and important precautions.