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 split Command: Divide Large Files into Smaller Parts

Linux split Command: Divide Large Files into Smaller Parts

Learn how to divide Large Files into Smaller Parts with the Linux split command, including practical examples, key options, and important precautions.

Linux Tutorial / Understand systemd Services, Boot, and Logs

Linux Tutorial / Understand systemd Services, Boot, and Logs

Understand Linux boot stages and systemd units, distinguish active services from boot enablement, and inspect current-boot logs with systemctl and journalctl.

Linux rmdir Command: Remove Empty Directories

Linux rmdir Command: Remove Empty Directories

Learn how to remove empty directories with Linux rmdir, delete empty parent paths, diagnose failures, and understand when rm -r is different.

Linux ethtool Command: Inspect Network Link and Driver Settings

Linux ethtool Command: Inspect Network Link and Driver Settings

Learn how to inspect Network Link and Driver Settings with the Linux ethtool command, including practical examples, key options, and important precautions.

Linux locate Command: Search Indexed File Paths Quickly

Linux locate Command: Search Indexed File Paths Quickly

Learn how Linux locate searches a filename database, how updatedb affects freshness, how to limit and filter matches, and when find is the better tool.

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 Tutorial / Navigate Directories with pwd, ls, cd, and tree

Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree

Use pwd, ls, cd, and tree to find your current location, inspect directories, navigate paths, and check where each command takes you.

Linux wc Command: Count Lines, Words, Characters, and Bytes

Linux wc Command: Count Lines, Words, Characters, and Bytes

Learn how to use the Linux wc command to count lines, words, characters, and bytes in files or standard input, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux dig Command: Query DNS Records in Detail

Linux dig Command: Query DNS Records in Detail

Learn how to query DNS Records in Detail with the Linux dig command, including practical examples, key options, and important precautions.

Linux free Command: Check Memory and Swap Usage

Linux free Command: Check Memory and Swap Usage

Learn how to use the Linux free command to inspect available memory, used memory, cache, and swap usage, with essential options, practical examples, output interpretation, and common troubleshooting tips.