ps

process managementLinux/Unix
The ps command is one of the most frequently used commands in Linux/Unix-like operating systems. ps The ps command displays information about active processes running on the system. It provides a snapshot of the current processes along with detailed information about resource usage, status, and other process attributes.

Quick Reference

Command Name:

ps

Category:

process management

Platform:

Linux/Unix

Basic Usage:

ps [options] [arguments]

Common Use Cases

  • 1

    Process monitoring

    Display information about running processes

  • 2

    Resource usage

    Monitor CPU, memory, and I/O usage of processes

  • 3

    Troubleshooting

    Diagnose issues with running processes

  • 4

    Scripting

    Use in shell scripts to monitor and manage processes

Syntax

ps [options]

Options

Option Description
-e, -A Select all processes
-a Select all processes except session leaders and processes not associated with a terminal
-f Full format listing (UID, PID, PPID, etc.)
-l Long format
-u username Display processes for a specific user
-p pid Select by process ID
-C command Select by command name
--sort=spec Sort output (e.g., --sort=-%cpu for CPU usage, highest first)
-o format, -o field1,field2 User-defined format or specific fields
-H Show process hierarchy (tree)
a Show processes of all users (BSD style)
u Display in user-oriented format (BSD style)
x Include processes without controlling terminals (BSD style)
j Jobs format
w Wide output (don't truncate command lines)

Examples

How to Use These Examples

The examples below show common ways to use the ps command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

#

Basic Usage:

ps

Show processes for the current shell with minimal information (PID, TTY, TIME, and CMD).

ps -ef

Display all processes in full format (standard Unix style).

ps aux

Show all processes for all users with detailed information (BSD style).

Filtering Processes:

ps -u username

Display processes for a specific user.

ps -C firefox

Find processes by command name.

ps -p 1234

Show information for a specific process ID.

Custom Output Format:

ps -eo pid,ppid,cmd,%cpu,%mem --sort=-%cpu

Display custom fields (PID, parent PID, command, CPU and memory usage) sorted by CPU usage (highest first).

ps -eo pid,user,stat,start,time,command

Show custom fields including process state, start time, and accumulated CPU time.

Tree View:

ps -ejH

Display process hierarchy in a tree format (Unix style).

ps axjf

Show BSD-style process tree.

Combining with Other Commands:

ps aux | grep firefox

Find all firefox processes using grep.

ps -eo pid,%cpu,%mem,cmd --sort=-%mem | head -n 10

Display the top 10 processes by memory usage.

Real-time Process Monitoring:

watch -n 1 'ps -eo pid,ppid,cmd,%cpu,%mem --sort=-%cpu | head'

Continuously monitor the top CPU-consuming processes, updating every second.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Understanding Process States:

  • R (Running): Process is running or runnable (in run queue)
  • S (Sleeping): Process is in interruptible sleep, waiting for an event
  • D (Disk Sleep): Uninterruptible sleep, typically waiting for I/O
  • T (Stopped): Process is stopped, either by a job control signal or because it's being traced
  • Z (Zombie): Defunct ("zombie") process, terminated but not reaped by its parent
  • I (Idle): Kernel thread (not shown in standard ps output)

Common Output Fields:

  • PID: Process ID - unique identifier for the process
  • PPID: Parent Process ID - the process that spawned this one
  • TTY: Terminal associated with the process
  • TIME: Cumulative CPU time used
  • CMD/COMMAND: Command with arguments
  • %CPU: CPU usage as a percentage
  • %MEM: Memory usage as a percentage
  • VSZ: Virtual memory size in KB
  • RSS: Resident Set Size - non-swapped physical memory used in KB
  • START/STIME: Time when the process started
  • STAT/S: Process state code
  • UID/USER: User ID or username of process owner

Style Differences:

  • Unix/POSIX Options: Use a dash prefix (e.g., ps -ef)
  • BSD Options: No dash prefix (e.g., ps aux)
  • GNU Long Options: Use double dashes (e.g., ps --forest)
  • Modern ps implementations accept all styles, allowing mixed syntax

Advanced Usage Tips:

  • Use ps with grep for fine-grained filtering (e.g., ps aux | grep [process])
  • The watch command can be combined with ps for continuous monitoring
  • For real-time, interactive process monitoring, consider using top or htop instead
  • Custom output formats with -o allow for focused troubleshooting and monitoring
  • Process hierarchy can be viewed with -H, f (--forest), or --forest options
  • Thread information can be shown with -L or H options

Security and Troubleshooting:

  • Regular users can only see their own processes unless using sudo or as root
  • Zombie processes (state Z) indicate processes that have terminated but not been "reaped" by their parent
  • High CPU usage in a process might indicate a busy process or possibly a malicious one
  • Process states can help identify stuck or malfunctioning processes
  • The start time of processes can help with forensic analysis

Related Commands:

  • top - Interactive process viewer with real-time updates
  • htop - Enhanced interactive process viewer
  • pgrep - Find processes by name and other attributes
  • pkill - Signal processes by name and other attributes
  • kill - Send signals to processes
  • nice - Run a program with modified scheduling priority
  • renice - Alter priority of running processes
  • pstree - Display a tree of processes

Tips & Tricks

1

Use the -e option to display all processes

2

Use the -f option to display full-format information

3

Use the -g option to display processes with a common group ID

4

Use the -l option to display processes in long format

5

Use the -o option to specify output columns

Common Use Cases

Process monitoring

Display information about running processes

Resource usage

Monitor CPU, memory, and I/O usage of processes

Troubleshooting

Diagnose issues with running processes

Scripting

Use in shell scripts to monitor and manage processes

System administration

Manage and optimize system resources

Related Commands

These commands are frequently used alongside ps or serve similar purposes:

Use Cases

1

Process monitoring

Display information about running processes

2

Resource usage

Monitor CPU, memory, and I/O usage of processes

3

Troubleshooting

Diagnose issues with running processes

4

Scripting

Use in shell scripts to monitor and manage processes

5

System administration

Manage and optimize system resources

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the ps command works in different scenarios.

$ ps
View All Commands