ps Command Guide
The ps (process status) command displays information about running processes. Learn how to monitor and manage processes effectively.
6 min read•Last updated: 2024
Dai Aoki
CEO at init, Inc. / CTO at US & JP startups / Creator of WebTerm
Quick Reference
Basic
psCurrent shell processesps auxAll processes (BSD)ps -efAll processes (Unix)Filter
ps -u userProcesses by userps -p PIDSpecific processps -C nameBy command nameFormat
ps -o pid,cmdCustom columnsps --forestProcess treeps auxwwWide outputCommon
ps aux | grep nameFind processps aux --sort=-%memSort by memoryps aux --sort=-%cpuSort by CPUDownloadable Image Preview
Failed to generate preview
Basic Usage
Without options, ps shows processes for the current terminal.
bash
psOutput 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 aux | All processes with detailed info (BSD style) |
| ps -ef | All processes in full format (Unix style) |
| ps -eF | Extra full format with more details |
| ps -u user | Processes for specific user |
| ps --forest | Show process tree |
View All Processes
BSD style (most common)
bash
ps auxColumns: USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND
Unix style
bash
ps -efColumns: UID, PID, PPID, C, STIME, TTY, TIME, CMD
Understanding Output Columns
Common Columns
| PID | Process ID |
| PPID | Parent Process ID |
| USER/UID | Process owner |
| %CPU | CPU usage percentage |
| %MEM | Memory usage percentage |
| VSZ | Virtual memory size (KB) |
| RSS | Resident Set Size - physical memory (KB) |
| STAT | Process state |
| TTY | Controlling terminal |
| TIME | Cumulative CPU time |
Process States (STAT column)
Process States
| R | Running or runnable |
| S | Sleeping (interruptible) |
| D | Uninterruptible sleep (usually IO) |
| T | Stopped |
| Z | Zombie (defunct) |
| < | High priority |
| N | Low priority |
| s | Session leader |
| l | Multi-threaded |
| + | Foreground process group |
Filtering Processes
By user
bash
# Processes for a specific user
ps -u username
# Or with BSD style
ps aux | grep usernameBy process name
bash
# Using grep
ps aux | grep nginx
# Using pgrep
pgrep -a nginxBy PID
bash
ps -p 1234
# Multiple PIDs
ps -p 1234,5678,9012Tip
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
pstreeCustom 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=-%cpuPractical Examples
Find top CPU consuming processes
bash
ps aux --sort=-%cpu | head -11Find top memory consuming processes
bash
ps aux --sort=-%mem | head -11Find zombie processes
bash
ps aux | awk '$8 ~ /Z/ { print }'Count processes by user
bash
ps -eo user | sort | uniq -c | sort -rnMonitor a specific process
bash
watch -n 1 "ps -p 1234 -o pid,%cpu,%mem,etime"Find parent process
bash
ps -o ppid= -p 1234Show threads
bash
ps -eLfRelated Commands
Process Management Commands
| top | Real-time process monitoring |
| htop | Interactive process viewer |
| pgrep | Find processes by name |
| pkill | Kill processes by name |
| pstree | Display process tree |
Summary
ps is essential for process monitoring. Key takeaways:
- Use
ps auxfor comprehensive process listing - Use
ps -effor Unix-style output with PPID - Use
--sortto sort by CPU or memory - Use
-ofor custom output format - Combine with
grepto filter by name