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:

Bash

Try both right now!

Bash

Typical ps aux columns:

text

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:

Bash

Typical ps -ef columns:

text

Extra: PPID = Parent Process ID (who started this process)

2. Super Useful Variations (copy-paste these!)

Bash

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?
    Bash
  • Find & kill hung Python script
    Bash
  • Check if nginx is running
    Bash
  • See zombie processes (bad – they are dead but not reaped)
    Bash
  • Monitor your ML training script
    Bash

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:

Bash

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! 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *