Chapter 27: Bash Process Status (ps)
What is ps? (super simple first)
ps = Process Status It shows a snapshot (photo at this moment) of the processes (running programs/tasks) on your Linux system.
Every program, script, service, browser tab, background job → is a process with:
- PID (Process ID – unique number)
- User who started it
- CPU % used right now
- Memory % / amount used
- Command name that started it
- Status (running, sleeping, zombie…)
- Parent process, start time, etc.
Without ps (or tools like top/htop), you can’t easily see what’s running, who’s eating CPU/RAM, or which process to kill when something hangs.
ps is static (one-time photo) top/htop are live (updating every second)
1. Most Important Styles / Formats (memorize these 3!)
There are two big traditions in Linux:
- BSD style (no dash before options) → very popular: ps aux
- UNIX style (with dash) → also common: ps -ef
The two commands everyone remembers forever:
|
0 1 2 3 4 5 6 7 |
ps aux # BSD style – MOST used by developers & admins ps -ef # UNIX style – also very common |
Try both right now!
|
0 1 2 3 4 5 6 |
ps aux | head -n 10 # first 10 lines only (because output is long) |
Typical ps aux columns:
|
0 1 2 3 4 5 6 7 8 9 10 |
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND arman 1234 0.0 0.5 123456 7890 pts/0 Ss 14:30 0:01 bash arman 5678 2.3 4.1 987654 34567 ? Sl 15:10 1:23 /usr/bin/python3 myscript.py root 1 0.0 0.1 23456 1234 ? Ss Feb24 0:05 /sbin/init ... |
Explanation of columns (very important!):
| Column | Meaning | Example value | Useful when… |
|---|---|---|---|
| USER | Who owns/runs the process | arman, root, www-data | Spot user processes |
| PID | Process ID (unique number) | 12345 | To kill: kill 12345 |
| %CPU | CPU usage right now (%) | 12.5 | Find CPU hogs |
| %MEM | RAM usage (%) | 3.8 | Find memory eaters |
| VSZ | Virtual memory size (KB) | 456789 | Total memory allocated |
| RSS | Resident Set Size – real RAM used (KB) | 34567 | Actual physical RAM |
| TTY | Terminal it’s attached to (? = none) | pts/0, ? | Background vs foreground |
| STAT | State (R=running, S=sleep, Z=zombie) | Sl, Ss, R | See if stuck/zombie |
| START | When it started | 14:30, Feb24 | Old processes |
| TIME | Total CPU time used | 0:45 | Long-running jobs |
| COMMAND | The command that started it | /usr/bin/firefox | Identify the program |
Now try the other style:
|
0 1 2 3 4 5 6 |
ps -ef | head -n 10 |
Typical ps -ef columns:
|
0 1 2 3 4 5 6 7 8 9 10 |
UID PID PPID C STIME TTY TIME CMD root 1 0 0 Feb24 ? 00:00:05 /sbin/init arman 1234 1230 0 14:30 pts/0 00:00:01 bash arman 5678 1234 0 15:10 pts/0 00:01:23 python3 myscript.py ... |
Extra: PPID = Parent Process ID (who started this process)
2. Super Useful Variations (copy-paste these!)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# Only your processes (most common daily) ps u # or ps -u $USER # All processes for user "arman" (case sensitive) ps -u arman # Top CPU users (combine with sort) ps aux --sort=-%cpu | head -15 # - = descending # Top memory users ps aux --sort=-%mem | head -10 # See only processes with "python" in name ps aux | grep python # But better – avoid showing grep itself ps aux | grep [p]ython # Tree view (parent-child relationship – very helpful!) ps -ejH # or ps axjf (BSD style) # Full details + wide output (no truncation) ps auxww # ww = very wide (no cut off commands) # Show only PID, command, %cpu, %mem (custom format) ps -eo pid,comm,%cpu,%mem --sort=-%cpu | head -10 # Everything about one PID (e.g. PID 1234) ps -p 1234 -o pid,ppid,user,%cpu,%mem,cmd |
3. Quick cheat-sheet table (save/print this!)
| What you want | Command example | Why useful |
|---|---|---|
| Your current processes | ps or ps u | Quick look |
| All processes (BSD – most popular) | ps aux | Full system view |
| All processes (UNIX style) | ps -ef | Classic format |
| Sort by CPU descending | ps aux --sort=-%cpu |
head -10 |
| Sort by memory descending | ps aux --sort=-%mem |
head -10 |
| Only your processes | ps -u $USER or ps u | Daily check |
| Processes by name | ps aux |
grep chromeorpgrep chrome |
| Tree view (parent → children) | ps -ejH or pstree | See relations |
| Custom columns | ps -eo pid,user,%cpu,%mem,cmd –sort=-%cpu | Clean report |
| Only PIDs (for scripting) | ps -eo pid –no-headers | Automation |
4. Real-life examples (Hyderabad developer style)
- Chrome eating RAM?
Bash0123456ps aux --sort=-%mem | grep chrome | head -5
- Find & kill hung Python script
Bash01234567ps aux | grep [p]ythonkill -9 5678 # use the PID
- Check if nginx is running
Bash0123456ps aux | grep [n]ginx
- See zombie processes (bad – they are dead but not reaped)
Bash0123456ps aux | grep 'Z'
- Monitor your ML training script
Bash0123456watch -n 2 "ps -p $(pgrep python) -o %cpu,%mem,cmd"
5. Pro tips
- ps aux > ps -ef for most people (shows %CPU, %MEM nicely)
- Use grep [firstletter]rest trick to avoid seeing grep line
- For live view → use top, htop, btop (install htop!)
- Kill safely: kill PID (gentle) → kill -9 PID (force)
- In scripts: ps -eo pid,comm | grep myservice → check if running
Now open your terminal and try these 3 right now:
|
0 1 2 3 4 5 6 7 8 |
ps aux | head -8 ps -u $USER ps aux --sort=-%cpu | head -5 |
Tell me:
- What’s the top CPU process on your machine right now?
- Or ask: “How to find all Java processes?” or “How to see total RAM used by all chrome tabs?”
We’ll write the exact command together! 😄
