Inspecting activity and resources
On this page
A command feels slow, and a report says something is nearly full. Before stopping programs or deleting files, you need to establish which resource the report describes. Process activity, working memory, and filesystem storage answer different questions.
By the end, you can choose an inspection tool, read its relevant fields and units, and distinguish free memory from filesystem capacity and directory usage.
Before you start
Section titled “Before you start”Finish Processes and identifiers, including its reset. Work in ~/lab, from the B04 setup. Reserve disposable ~/lab/b13 for two small files; use the reset before repeating this exercise.
Your PIDs, times, CPU percentages, memory figures, filesystem sizes, and directory allocation may differ. These are real lab-container captures, not a model of your computer. The container has few processes and runs a capture program as PID 1, not systemd. Memory and filesystem reports reflect the Docker Desktop VM’s environment, not a physical machine’s installed RAM or drive. The container’s / uses an overlay filesystem.
Take a snapshot of a known wait
Section titled “Take a snapshot of a known wait”Start a harmless waiting process and save its PID:
sleep 300 &watch=$!ps -p "$watch" -o pid,stat,pcpu,pmem,commAs in B13.1, & starts the command and returns the prompt at once; B13.4 explains background jobs in full. watch here is a shell variable, not a command you need to install. The -p selection confines the listing to your own wait.
| Field | Meaning in this snapshot |
|---|---|
PID |
The selected process’s identity; captured 19 |
STAT |
Process state; captured S, interruptible sleep, waiting for an event |
%CPU |
CPU time as a percentage of elapsed lifetime for this ps report; captured 0.0 |
%MEM |
Resident memory as a percentage of physical memory reported to the tool; captured 0.0 |
COMMAND |
Executable name from the comm field; captured sleep |
A process can exist while using almost no CPU. Predict first: should an idle sleep show sustained heavy CPU usage?
Run it, then compare with your guess
No. The capture shows state S and rounded CPU and memory values of 0.0. Rounded zero does not mean a process occupies no memory. Sleep is waiting rather than repeatedly calculating.
Watch an updating process view
Section titled “Watch an updating process view”top -p "$watch"top is an interactive, full-screen monitor. -p selects the saved PID rather than displaying every visible process. On your terminal the display refreshes in place. Press q to quit; Ctrl+C also exits the tested top and is the exit recorded below.
The replay captures one initial interactive screen before Ctrl+C. It does not reproduce continuous screen refreshes. This is interactive top, not batch mode, and its initial CPU sample is not evidence of long-term performance.
learner@rootvolt:~/lab$ sleep 300 &[1] 19learner@rootvolt:~/lab$ watch=$!learner@rootvolt:~/lab$ ps -p "$watch" -o pid,stat,pcpu,pmem,comm PID STAT %CPU %MEM COMMAND
19 S 0.0 0.0 sleeplearner@rootvolt:~/lab$ top -p "$watch"top - 12:30:53 up 1:44, 0 user, load average: 0.02, 0.08, 0.07
Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 0.5 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 7790.7 total, 6532.3 free, 880.4 used, 530.0 buff/cache
MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 6910.2 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19 learner 20 0 5696 2036 1928 S 0.0 0.0 0:00.00 sleep ^Clearner@rootvolt:~/lab$ Steps (12)
- Type
sleep 300 & - Press Enter
- Output:
[1] 19 - Type
watch=$! - Press Enter
- Type
ps -p "$watch" -o pid,stat,pcpu,pmem,comm - Press Enter
- Output:
PID STAT %CPU %MEM COMMAND 19 S 0.0 0.0 sleep - Type
top -p "$watch" - Press Enter
- Output:
top - 12:30:53 up 1:44, 0 user, load average: 0.02, 0.08, 0.07 Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.5 sy, 0.0 ni, 99.5 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 7790.7 total, 6532.3 free, 880.4 used, 530.0 buff/cache MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 6910.2 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 19 learner 20 0 5696 2036 1928 S 0.0 0.0 0:00.00 sleep - Press Ctrl + C — Interrupt top and return to the shell
Look at the task row, below the summary. PID connects it to your saved identifier. RES is resident memory, the part held in RAM; VIRT is virtual address space, not a count of RAM bytes used. In this default top view, task memory values are in KiB unless their displayed suffix or configuration changes the scale. The summary explicitly labels memory in MiB.
%CPU in an updating top view describes activity over a sampling interval, unlike ps’s lifetime average. %MEM relates resident memory to reported physical memory. TIME+ is accumulated CPU time, not how long the command has existed. You do not need the priority fields to answer whether this known wait is busy.
Top’s memory summary is system information, even with -p selecting one task. Selecting a row does not allocate a private pool of RAM to that process.
Separate RAM from filesystem space
Section titled “Separate RAM from filesystem space”free -hdf -h /learner@rootvolt:~/lab$ free -h total used free shared buff/cache available
Mem: 7.6Gi 876Mi 6.4Gi 3.8Mi 530Mi 6.8Gi
Swap: 2.0Gi 0B 2.0Gilearner@rootvolt:~/lab$ df -h /Filesystem Size Used Avail Use% Mounted on
overlay 1007G 3.3G 953G 1% /learner@rootvolt:~/lab$ Steps (6)
- Type
free -h - Press Enter
- Output:
total used free shared buff/cache available Mem: 7.6Gi 876Mi 6.4Gi 3.8Mi 530Mi 6.8Gi Swap: 2.0Gi 0B 2.0Gi - Type
df -h / - Press Enter
- Output:
Filesystem Size Used Avail Use% Mounted on overlay 1007G 3.3G 953G 1% /
On a narrow screen these wide rows wrap. Here are the same captured values, column by column:
| Report and column | Captured value |
|---|---|
free, Mem: total |
7.6Gi |
free, Mem: used |
876Mi |
free, Mem: free |
6.4Gi |
free, Mem: buff/cache |
530Mi |
free, Mem: available |
6.8Gi |
free, Swap: total / used |
2.0Gi / 0B |
df, Filesystem |
overlay |
df, Size / Used / Avail |
1007G / 3.3G / 953G |
df, Use% / Mounted on |
1% / / |
free reports memory. -h chooses human-readable units such as Mi and Gi, powers of 1024. The Mem: row describes RAM; Swap: describes backing space used for swapped memory pages. Do not add swap to RAM and call the sum physical memory.
Look at available, an estimate of memory available for starting applications without swapping. free describes unused memory; some buffers and caches can be reclaimed, so those two columns differ. A small free value alone does not establish that the system is out of usable memory. The captured available value is 6.8Gi; yours will differ.
df answers a storage question: how much capacity belongs to the filesystem containing /? Size, Used, Avail, and Use% describe that filesystem, not RAM. -h uses powers of 1024 with suffixes such as G. Here overlay identifies the container’s layered root filesystem. Its reported 1007G size is not a disk assigned exclusively to this container. Available space can also differ from size minus used because filesystem accounting can reserve space.
Measure one directory’s files
Section titled “Measure one directory’s files”Prepare two files with known byte counts:
mkdir -p ~/lab/b13head -c 65536 /dev/zero > ~/lab/b13/small.binhead -c 131072 /dev/zero > ~/lab/b13/large.bindu -h ~/lab/b13/*.bindu -sh ~/lab/b13/dev/zero supplies zero bytes. head -c limits how many bytes are written, so these files are bounded at 64 KiB and 128 KiB. Redirection creates or overwrites only these disposable exercise paths.
learner@rootvolt:~/lab$ mkdir -p ~/lab/b13learner@rootvolt:~/lab$ head -c 65536 /dev/zero > ~/lab/b13/small.binlearner@rootvolt:~/lab$ head -c 131072 /dev/zero > ~/lab/b13/large.binlearner@rootvolt:~/lab$ du -h ~/lab/b13/*.bin128K /home/learner/lab/b13/large.bin
64K /home/learner/lab/b13/small.binlearner@rootvolt:~/lab$ du -sh ~/lab/b13196K /home/learner/lab/b13learner@rootvolt:~/lab$ Steps (12)
- Type
mkdir -p ~/lab/b13 - Press Enter
- Type
head -c 65536 /dev/zero > ~/lab/b13/small.bin - Press Enter
- Type
head -c 131072 /dev/zero > ~/lab/b13/large.bin - Press Enter
- Type
du -h ~/lab/b13/*.bin - Press Enter
- Output:
128K /home/learner/lab/b13/large.bin 64K /home/learner/lab/b13/small.bin - Type
du -sh ~/lab/b13 - Press Enter
- Output:
196K /home/learner/lab/b13
du estimates filesystem space used by the specified files and directory contents. -s gives a summary total instead of a recursive listing; -h makes units readable. The captured directory total is 196K, rather than the files’ combined 192K, because the directory itself also occupies space here.
Allocation depends on the filesystem. Sparse files, compression, and shared data can make disk usage differ from a file’s apparent byte length. This exercise writes actual zero bytes rather than creating sparse files with truncate. Your allocation can still differ. A du total for this one directory is not a measurement of the entire filesystem’s free capacity.
Mistakes to recognize
Section titled “Mistakes to recognize”Reading df as free RAM. Follow the labels: a filesystem and mount path belong to storage; a Mem: row belongs to memory.
Comparing numbers without their units. 196K and 6.8Gi describe different scales as well as different resources. Preserve the units when reporting evidence.
Diagnosing the VM from the container alone. These tools report what their environment exposes. Container-visible tasks and Docker VM totals do not describe all processes and resources on a physical host.
Try it yourself
Section titled “Try it yourself”Goal: Choose evidence for three separate reports: a waiting command may be busy, a directory may contain large files, and the filesystem may be filling up. Explain why one tool cannot settle all three.
Solution
Use ps or top for the selected process’s state and CPU activity. Use du for the directory’s allocated usage, and df for the containing filesystem’s capacity. Free answers a separate RAM question. Do not delete files merely because a memory report has a small free column.
Reset this lesson
Section titled “Reset this lesson”kill "$watch"wait "$watch"ps -p "$watch" -o pid,commrm ~/lab/b13/small.bin ~/lab/b13/large.binrmdir ~/lab/b13unset watchThese commands terminate only your saved waiting process, collect its completion, and check that it is absent. Remove only the two exercise files, then their empty directory. The captured ps prints a header with no row and returns 1; rmdir succeeds silently.
learner@rootvolt:~/lab$ kill "$watch"learner@rootvolt:~/lab$ wait "$watch"[1]+ Terminated sleep 300learner@rootvolt:~/lab$ ps -p "$watch" -o pid,comm PID COMMANDlearner@rootvolt:~/lab$ rm ~/lab/b13/small.bin ~/lab/b13/large.binlearner@rootvolt:~/lab$ rmdir ~/lab/b13learner@rootvolt:~/lab$ unset watchlearner@rootvolt:~/lab$ Steps (14)
- Type
kill "$watch" - Press Enter
- Type
wait "$watch" - Press Enter
- Output:
[1]+ Terminated sleep 300 - Type
ps -p "$watch" -o pid,comm - Press Enter
- Output:
PID COMMAND - Type
rm ~/lab/b13/small.bin ~/lab/b13/large.bin - Press Enter
- Type
rmdir ~/lab/b13 - Press Enter
- Type
unset watch - Press Enter
pstakes a snapshot; interactivetopupdates its screen.freedescribes RAM and swap, with available memory distinct from unused memory.dfdescribes filesystem capacity;dumeasures usage of selected files and directories.- Check units and environment boundaries before interpreting resource figures.
Next, Signals and stopping processes compares a cooperative termination request with forceful termination.