Terminal GuideTerminal Guide

ps Command Guide

The ps (process status) command displays information about running processes. Learn how to monitor and manage processes effectively.

6 min readLast updated: 2024
Dai Aoki

Dai Aoki

CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm

Quick Reference

Basic

psCurrent shell processes
ps auxAll processes (BSD)
ps -efAll processes (Unix)

Filter

ps -u userProcesses by user
ps -p PIDSpecific process
ps -C nameBy command name

Format

ps -o pid,cmdCustom columns
ps --forestProcess tree
ps auxwwWide output

Common

ps aux | grep nameFind process
ps aux --sort=-%memSort by memory
ps aux --sort=-%cpuSort by CPU

Downloadable Image Preview

Failed to generate preview

Basic Usage

Without options, ps shows processes for the current terminal.

bash
ps

Output columns: PID (Process ID), TTY (Terminal), TIME (CPU time), CMD (Command).

Common Option Styles

ps supports three option styles: Unix (-), BSD (no dash), and GNU (--).

Popular Option Combinations

ps auxAll processes with detailed info (BSD style)
ps -efAll processes in full format (Unix style)
ps -eFExtra full format with more details
ps -u userProcesses for specific user
ps --forestShow process tree

View All Processes

BSD style (most common)

bash
ps aux

Columns: USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND

Unix style

bash
ps -ef

Columns: UID, PID, PPID, C, STIME, TTY, TIME, CMD

Understanding Output Columns

Common Columns

PIDProcess ID
PPIDParent Process ID
USER/UIDProcess owner
%CPUCPU usage percentage
%MEMMemory usage percentage
VSZVirtual memory size (KB)
RSSResident Set Size - physical memory (KB)
STATProcess state
TTYControlling terminal
TIMECumulative CPU time

Process States (STAT column)

Process States

RRunning or runnable
SSleeping (interruptible)
DUninterruptible sleep (usually IO)
TStopped
ZZombie (defunct)
<High priority
NLow priority
sSession leader
lMulti-threaded
+Foreground process group

Filtering Processes

By user

bash
# Processes for a specific user
ps -u username

# Or with BSD style
ps aux | grep username

By process name

bash
# Using grep
ps aux | grep nginx

# Using pgrep
pgrep -a nginx

By PID

bash
ps -p 1234

# Multiple PIDs
ps -p 1234,5678,9012
Tip
When using grep with ps, the grep process itself appears in the output. Use grep [n]ginx orgrep nginx | grep -v grep to exclude it.

Process Tree

bash
# Show process hierarchy
ps --forest

# Or combined with aux
ps auxf

# Or use pstree for better visualization
pstree

Custom Output Format

bash
# Select specific columns
ps -eo pid,user,%cpu,%mem,command

# Sort by memory usage
ps -eo pid,user,%mem,command --sort=-%mem

# Sort by CPU usage
ps -eo pid,user,%cpu,command --sort=-%cpu

Practical Examples

Find top CPU consuming processes

bash
ps aux --sort=-%cpu | head -11

Find top memory consuming processes

bash
ps aux --sort=-%mem | head -11

Find zombie processes

bash
ps aux | awk '$8 ~ /Z/ { print }'

Count processes by user

bash
ps -eo user | sort | uniq -c | sort -rn

Monitor a specific process

bash
watch -n 1 "ps -p 1234 -o pid,%cpu,%mem,etime"

Find parent process

bash
ps -o ppid= -p 1234

Show threads

bash
ps -eLf

Process Management Commands

topReal-time process monitoring
htopInteractive process viewer
pgrepFind processes by name
pkillKill processes by name
pstreeDisplay process tree

Summary

ps is essential for process monitoring. Key takeaways:

  • Use ps aux for comprehensive process listing
  • Use ps -ef for Unix-style output with PPID
  • Use --sort to sort by CPU or memory
  • Use -o for custom output format
  • Combine with grep to filter by name

Related Articles