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 info Command: Browse GNU Documentation

Linux info Command: Browse GNU Documentation

Learn how to use the Linux info command to browse hierarchical GNU manuals and navigate Info nodes, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux mkdir Command: Create Directories and Parent Paths

Linux mkdir Command: Create Directories and Parent Paths

Learn how to create directories with Linux mkdir, build missing parent paths, set permissions, understand umask behavior, and verify results in scripts.

Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux hostnamectl Command: Show and Change the Host Name

Linux hostnamectl Command: Show and Change the Host Name

Learn how to show and Change the Host Name with the Linux hostnamectl command, including practical examples, key options, and important precautions.

Linux journalctl Command: Read systemd Logs

Linux journalctl Command: Read systemd Logs

Learn how to read systemd Logs with the Linux journalctl command, including practical examples, key options, and important precautions.

Linux comm Command: Compare Two Sorted Files

Linux comm Command: Compare Two Sorted Files

Learn how to compare Two Sorted Files with the Linux comm command, including practical examples, key options, and important precautions.

Linux killall Command: Signal Processes by Name

Linux killall Command: Signal Processes by Name

Learn how to signal Processes by Name with the Linux killall command, including practical examples, key options, and important precautions.

Linux printenv Command: Print Environment Variable Values

Linux printenv Command: Print Environment Variable Values

Learn how to use the Linux printenv command to print all environment variables or selected variable values, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux nc Command: Test TCP and UDP Connections

Linux nc Command: Test TCP and UDP Connections

Learn how to test TCP and UDP Connections with the Linux nc command, including practical examples, key options, and important precautions.

Linux Tutorial / File System Basics: Paths and Key Directories

Linux Tutorial / File System Basics: Paths and Key Directories

Understand the Linux directory tree, read absolute and relative paths, and learn what common directories such as /home, /etc, and /var are used for.