ps
Overview
ps snapshots processes. Linux ps accepts both BSD-style (ps aux) and UNIX-style (ps -ef) option sets — mixing styles works but can confuse; pick one family per command.
Syntax
ps [options]Common Invocations
| Form | Description |
|---|---|
ps aux |
BSD: all users, with CPU/MEM |
ps -ef |
UNIX: full listing |
ps -u USER |
User’s processes |
ps -p PID |
Specific PID |
ps -C name |
By command name |
ps --forest / f |
Tree view |
Useful output controls: -o pid,ppid,user,pcpu,%mem,stat,cmd (custom columns), --sort=-%mem.
Key Use Cases
- Identify heavy CPU/memory processes
- Find PIDs for signaling
- Inspect command lines and parentage
- Script process inventory
Examples with Explanations
Classic full lists
ps aux | head
ps -ef | headTop memory consumers
ps aux --sort=-%mem | head -n 15Top CPU
ps aux --sort=-%cpu | head -n 15Custom columns
ps -eo pid,ppid,user,%cpu,%mem,stat,etime,cmd --sort=-%cpu | headBy user / name
ps -u www-data -o pid,cmd
ps -C nginx -o pid,cmdTree
ps auxf | less
# or
pstree -ap | lessOne PID detail
ps -p 1 -o pid,user,cmd,lstartThreads
ps -eLf | head
# or: ps -p PID -LUnderstanding Output
- STAT codes:
Rrunning,Ssleep,Duninterruptible,Zzombie,Tstopped;+foreground,lmulti-threaded, etc.
- %CPU is not normalized the same as
topover long intervals.
- VSZ/RSS memory columns differ (virtual vs resident).
Notes & Pitfalls
psis a snapshot; usetop/htopfor continuous view.
- Prefer
pgrepwhen you only need PIDs by name.
- Kernel threads appear in brackets
[kthreadd].
Additional Resources
man ps