Chapter 28: Bash List Processes (top)

What is top? (super simple first)

top = shows a live, updating view of all running processes on your Linux system + summary information about CPU, memory, swap, tasks, load average.

It’s the most popular interactive process viewer – like Task Manager on Windows, but much more powerful and lightweight.

Key differences from ps:

  • ps → one-time photo (static snapshot)
  • top → live video (refreshes every ~3 seconds by default)

You run it, it stays open, updates automatically, and you can interact with it (sort, kill, change view, etc.).

Most people use top daily to:

  • See which program is eating CPU / RAM right now
  • Find hung / zombie processes
  • Check system load when something feels slow
  • Quickly kill a bad process
  • Watch memory / swap usage live

1. Just run it (try right now!)

Bash

You will see something like this (example from a typical laptop):

text

2. Understand every part of the screen (very important!)

First 5 summary lines:

  1. top – time up days,hours:min, users, load average: 1min 5min 15min

    • load average 0.85 0.60 0.45 → good (below number of CPU cores = relaxed)
    • 3.2 4.1 5.0 → overloaded (system struggling)
  2. Tasks: total / running / sleeping / stopped / zombie

    • zombie = dead but parent didn’t collect → bad sign
  3. %Cpu(s): us (user/apps), sy (system/kernel), ni (nice/low prio), id (idle), wa (waiting for disk I/O), hi/si (hardware/software interrupts), st (steal – virtual machine)

    • High id (90%+) = idle & happy
    • High wa = disk bottleneck (slow HDD/SSD/full disk)
  4. MiB Mem / MiB Swap

    • total / free / used / buff/cache
    • avail Mem = what you can still use comfortably
    • Swap used > 0 → RAM is full → slow system
  5. Process list columns (most important!)

Column Meaning Good value example When to worry
PID Process ID 12345 To kill it
USER Who owns the process arman, root Unknown user?
PR / NI Priority / Nice value 20 / 0 -20 = highest prio
VIRT Virtual memory (total allocated) 2.4g Big is ok
RES Resident memory (real RAM used) 456m High = eating RAM
SHR Shared memory 123m Libraries
S State (R=run, S=sleep, D=uninterruptible, Z=zombie, T=stopped) S (sleeping) most common Z or D = problem
%CPU CPU usage this update 12.5 100% = busy
%MEM RAM usage % 4.2 >10–20% suspicious
TIME+ Total CPU time used since start 45:12.34 Very high = long runner
COMMAND Name of the command firefox-bin Identify culprit

3. Most useful keys inside top (learn these!)

Key What it does When to use
q Quit Finish
1 Show each CPU core separately Multi-core laptop/server
Shift+P Sort by %CPU (default) Find CPU eater
Shift+M Sort by %MEM Find RAM eater
Shift+T Sort by TIME+ (longest running) Old processes
k Kill process (type PID, then signal) Kill hung app
r Renice (change priority) Lower prio of bad process
f Field management (add/remove/sort columns) Customize view
z Toggle color/monochrome Easier reading
c Toggle full command line vs name See full path/args
Shift+C Toggle highlight of changed lines See what changed
d or s Change refresh delay (default 3s) Slower = less CPU use
Shift+W Save current settings to ~/.toprc Remember layout

4. Real-life examples you will use daily

Bash

5. Quick cheat-sheet table

Goal How to do it in top Notes
See live CPU/RAM/processes Just run top Default view
Sort by CPU usage Press Shift+P Default actually
Sort by memory usage Press Shift+M Very common
Kill a process Press k → type PID → Enter → 15 or 9 15 = gentle, 9 = force
Show per-core CPU Press 1 Multi-core systems
See full command line Press c See arguments
Save your favorite view Customize → Shift+W ~/.toprc
Only your user top -u $USER Cleaner
Batch / script snapshot top -b -n 1 > snapshot.txt Automation

6. Pro tips & next steps

  • If top feels old → install htop or btop (much prettier)
    Bash
  • High wa in %Cpu → check disk with iostat -x 1
  • Swap used a lot → you need more RAM or close heavy apps
  • Load average > number of cores for long time → system overloaded

Now open your terminal and try:

Bash

Tell me:

  • What’s your current load average? (e.g. 0.45 0.32 0.28)
  • Which process is using the most %CPU or %MEM right now?

Or ask:

  • “How to kill a process from top safely?”
  • “What does high wa mean and how to fix?”
  • “htop vs top vs glances – which one should I use?”

We’ll go deeper together! 😄

You may also like...

Leave a Reply

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