ps displays information about running processes. It’s essential for monitoring and managing system processes.
Synopsis
ps [OPTIONS]
Common Options
| Option | Description |
|---|
aux | All processes, user-oriented format |
-ef | All processes, full format |
-u USER | Processes for specific user |
-p PID | Specific process by PID |
--forest | Show process tree |
-o FORMAT | Custom output columns |
Examples
Show all processes (BSD style)
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 169592 13092 ? Ss Jan15 0:03 /sbin/init
root 2 0.0 0.0 0 0 ? S Jan15 0:00 [kthreadd]
greys 12345 0.5 1.2 456789 98765 pts/0 Ss 10:00 0:05 -bash
Show all processes (System V style)
$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jan15 ? 00:00:03 /sbin/init
greys 12345 12340 0 10:00 pts/0 00:00:05 -bash
Show processes for current user
Show specific process
$ ps -p 1234
$ ps -p 1234 -o pid,ppid,cmd,%cpu,%mem
Process tree
$ ps --forest
$ ps auxf # With forest
$ ps -eo pid,ppid,user,%cpu,%mem,cmd --sort=-%cpu | head
Find process by name
$ ps aux | grep nginx
$ pgrep -a nginx # Alternative
Understanding ps aux Output
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
│ │ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │ └─ Command
│ │ │ │ │ │ │ │ │ └─ CPU time
│ │ │ │ │ │ │ │ └─ Start time
│ │ │ │ │ │ │ └─ State (S=sleep, R=running)
│ │ │ │ │ │ └─ Terminal
│ │ │ │ │ └─ Resident memory (KB)
│ │ │ │ └─ Virtual memory (KB)
│ │ │ └─ Memory %
│ │ └─ CPU %
│ └─ Process ID
└─ Owner
Process States (STAT)
| Code | Meaning |
|---|
| R | Running |
| S | Sleeping |
| D | Uninterruptible sleep |
| Z | Zombie |
| T | Stopped |
Tips
- Use pgrep:
pgrep nginx is cleaner than ps aux | grep nginx - Watch processes:
watch -n 1 'ps aux --sort=-%cpu | head' - For real-time: Use
top or htop instead - Find parent: Use
ps -p PID -o ppid= to get parent PID
See Also
- top — Real-time process viewer
- htop — Interactive process viewer
- kill — Send signals to processes
- pgrep — Find processes by name
Tutorials