The Linux ps Command: Finding What's Eating Your CPU
The Linux ps Command: Finding What's Eating Your CPU
The server was sluggish. "Too many processes," they said. But which ones? I typed "ps" and got a screen full of data I couldn't understand.
That day I learned: ps is your window into what's running. Master it.
First ps Output
ps
Resulted in:
PID TTY TIME CMD
1 ? 00:00:02 systemd
412 ? 00:00:01 sshd
823 pts/0 00:00:00 bash
824 pts/0 00:00:00 ps
This shows processes for the current terminal only. Not helpful.
BSD style (aux)
ps aux
Shows all processes for all users:
- a = all users
- u = user-oriented format
- x = include processes without terminal
POSIX style (-ef)
ps -ef
Standard format:
- e = every process
- f = full format
Understanding ps Columns
USER vs UID
ps -eo user,pid,cmd
User, process ID, command.
CPU and MEM
ps -eo user,pid,pcpu,pmem,cmd
Shows %CPU and %MEM usage.
Sorting by CPU
ps -eo pcpu,pid,user,cmd --sort=-pcpu | head -10
Top CPU consumers.
ps Commands That Work
Find a specific process
ps aux | grep nginx
Classic pipeline.
Find by name
ps -C nginx
By command name.
Find by user
ps -U www-data
All processes for user.
Full command with arguments
ps -efww
Wide output for full commands.
Tree view
ps -ejH
Shows parent-child relationships.
Detailed view
ps -Fal
Extra detailed format.
The ps Command Builder
Building ps commands with the right fields is easier with the ps Command Builder:
- Select columns from a list
- Choose format easily
- Copy the exact command you need
Common ps Patterns
Top 10 by CPU
ps -eo pcpu,pid,user,args --sort=-pcpu | head -n 11
Skip header row (11 = 10 + 1).
Top 10 by memory
ps -eo pmem,pid,user,args --sort=-pmem | head -n 11
All Java processes
ps -C java -o pid=,cmd=
Processes on specific port
lsof -i :8080 | tail -n +2 | awk '{print $2}' | xargs ps -p
Zombie processes
ps aux | grep "defunct"
Quick Reference
| Command | What It Does |
|---|---|
ps |
Simple list |
ps aux |
BSD all users |
ps -ef |
POSIX full |
ps -C name |
By command |
ps -U user |
By user |
ps -eo columns |
Custom columns |
ps --sort=col |
Sort output |
Lessons Learned
-
ps aux is most common — shows everything.
-
Sort by using --sort=-column — minus for descending.
-
Use -eo for custom columns — exactly what you need.
-
Combine with grep — filter specific processes.
-
ps shows current state — for real-time, use top.
Conclusion: ps Is Your Process Lens
ps tells you exactly what's running—use it to debug performance issues.
The ps Command Builder makes selecting columns easy.
