Finding the Process
Outcome: starting from a few hundred processes, you arrive at the one you meant — by sorting the list so it floats up, filtering until only it remains, unfolding the tree, or opening it up to read its details.
Sorting: the busiest first
The list is sorted by whatever the
control in its header says: ← cpu lazy
→. The Left and Right arrow
keys move that choice through the
columns — pid, program, command,
threads, user, memory, cpu — and the
list re-sorts at once. (The lazy in
"cpu lazy" is btop's honest word for a
smoothed reading that does not jump at
every flicker; pressing Right once more
from it reaches "cpu direct", the raw
figure.)
Sorting by memory answers the other
great question. The lab, with Right
pressed until the header read
← memory →:
Pid: Program: Command: Threads: User: MemB
68654 zig zig init 2 root 648M
32 hatch /opt/hatch/bin/hatch daemon --runt 14 root 360M
68460 python3 python3 -c blob = bytearray(200*1 1 root 205M
69831 bun /home/hatch/workspace/build-check/ 7 root 18M
68819 bun /home/hatch/workspace/build-check/ 2 root 11M
Third row is the lab's memory tenant:
a Python program holding a 200 MB block
it made on purpose, reading exactly the
205M you would predict. Two practical
notes. The r key reverses any sort,
which is how you find the smallest or
oldest instead. And one honest surprise
from the lab's keyboard work: keys sent
faster than btop's refresh can be missed
entirely — if a keypress seems ignored,
press it once, on its own, and watch;
the screen is not being rude, it is
busy. Chapter 11 says more.
Filtering: keep only the matches
Press f (or /) and type. The list
narrows as the header takes your text —
while typing it shows f orchard ↵,
meaning press Enter to keep this, and
once kept, f orchard del, meaning
the Delete key clears it. The lab
typed orchard, its name for a test
process that sleeps for fifteen minutes
doing absolutely nothing, and the few
hundred processes became:
Pid: Program: Command: Threads: User: MemB
68458 orchard-worker ./orchard-worker 900 1 root 1.6M
Two things filtering teaches quickly.
It matches the command as well as
the name, so filtering for a word in
some path or argument works — and can
also catch innocent processes whose
command lines merely contain the word.
And a filter starting with ! is a
regular expression (a pattern
language the Regular Expressions guide
in this series teaches), for matches a
plain word cannot express. Delete
clears the filter; the full crowd
returns. The command line offers the
same trick at startup: btop -f orchard
opens already filtered.
The tree: who started whom
Processes are started by other
processes, and the flat list hides it.
Press e (or the tree button) and
the list becomes a family tree:
Tree: Threads: User: MemB Cpu%
├─32 hatch (/opt/hatch/bin/hatch daemon --runtime-cell-lea) 14 root 403M ⣀⣀⣀⣀⣀ 5.7
[-]─726 hatch-execd (/opt/hatch/bin/hatch-execd --runtime-c) 2 root 7.5M ⣀⣀⣀⣀⣀ 2.0
│ [-]─70854 bash (/bin/bash --norc --noprofile -c umask 00) 1 root 3.5M ⣀⣀⣀⣀⣀ 0.0
│ └─70859 sleep 1 root 1.5M ⣀⣀⣀⣀⣀ 0.0
[-]─1 systemd (/usr/lib/systemd/systemd) 1 root 5.2M ⣀⣀⣀⣀⣀ 0.0
[-]─68517 tmux: server (tmux) 1 root 3.9M ⣀⣀⣀⣀⡀ 0.0
Parents sit above their children; ├─
and └─ connect them; a [-] marks a
branch you can fold with the Spacebar
(E folds or unfolds everything). The
tree is how you learn that the process
eating the machine belongs to a program
you recognise three generations up — and
chapter 5 is where that knowledge keeps
you from stopping a child and leaving
its parent to simply restart it. The
lab left tree view on in its config
file, which is chapter 8's worked
example.
One process, opened up
Select a row with the Up and Down keys and press Enter: the list gives way to a detail panel for that process — its full command line (untruncated at last), its owner and state, and graphs of its own processor and memory use. The lab read, in its panel, a memory figure of 5.28% of the machine for the process it examined — the percentage form of the same fact the MemB column states in megabytes, and the panel is where the two agree in writing. Esc returns to the list.
Two footer companions deserve a
sentence each. Follow (F) pins the
selection to a process so the highlight
stays with it as the list re-sorts —
without it, a row you are watching
under a busy sort dances away between
refreshes. And u pauses the list
entirely, which is the polite way to
read a screen that keeps moving.
Check: on your own machine, sort by
memory and name the top process; filter
for a program you know is running and
watch the list fall to it; press e
and find one child whose parent you
recognise. Chapter 5 acts on what you
have found.