Skip to content

Inspecting activity and resources

Module
Processes and System Information
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab container), GNU Bash 5.2.21
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.

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.

Start a harmless waiting process and save its PID:

Terminal window
sleep 300 &
watch=$!
ps -p "$watch" -o pid,stat,pcpu,pmem,comm

As 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.

Terminal window
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.

A snapshot and an interactive top screen
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$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. A selected sleep appears in a ps snapshot and one real interactive top screen; Ctrl+C exits the monitor while sleep remains alive.
Steps (12)
  1. Type sleep 300 &
  2. Press Enter
  3. Output: [1] 19
  4. Type watch=$!
  5. Press Enter
  6. Type ps -p "$watch" -o pid,stat,pcpu,pmem,comm
  7. Press Enter
  8. Output: PID STAT %CPU %MEM COMMAND 19 S 0.0 0.0 sleep
  9. Type top -p "$watch"
  10. Press Enter
  11. 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
  12. 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.

Terminal window
free -h
df -h /
Memory and filesystem capacity
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$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. free reports memory and swap, while df reports capacity of the filesystem containing the selected path /.
Steps (6)
  1. Type free -h
  2. Press Enter
  3. 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
  4. Type df -h /
  5. Press Enter
  6. 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.

Prepare two files with known byte counts:

Terminal window
mkdir -p ~/lab/b13
head -c 65536 /dev/zero > ~/lab/b13/small.bin
head -c 131072 /dev/zero > ~/lab/b13/large.bin
du -h ~/lab/b13/*.bin
du -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.

Measure two known-size files
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$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. Two bounded files occupy 64K and 128K in this capture; the directory total is 196K, including directory allocation.
Steps (12)
  1. Type mkdir -p ~/lab/b13
  2. Press Enter
  3. Type head -c 65536 /dev/zero > ~/lab/b13/small.bin
  4. Press Enter
  5. Type head -c 131072 /dev/zero > ~/lab/b13/large.bin
  6. Press Enter
  7. Type du -h ~/lab/b13/*.bin
  8. Press Enter
  9. Output: 128K /home/learner/lab/b13/large.bin 64K /home/learner/lab/b13/small.bin
  10. Type du -sh ~/lab/b13
  11. Press Enter
  12. 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.

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.

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.

Terminal window
kill "$watch"
wait "$watch"
ps -p "$watch" -o pid,comm
rm ~/lab/b13/small.bin ~/lab/b13/large.bin
rmdir ~/lab/b13
unset watch

These 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.

Remove only the practice workload and files
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$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. The saved sleep is terminated and absent from ps; both bounded files and their empty directory are removed.
Steps (14)
  1. Type kill "$watch"
  2. Press Enter
  3. Type wait "$watch"
  4. Press Enter
  5. Output: [1]+ Terminated sleep 300
  6. Type ps -p "$watch" -o pid,comm
  7. Press Enter
  8. Output: PID COMMAND
  9. Type rm ~/lab/b13/small.bin ~/lab/b13/large.bin
  10. Press Enter
  11. Type rmdir ~/lab/b13
  12. Press Enter
  13. Type unset watch
  14. Press Enter
  • ps takes a snapshot; interactive top updates its screen.
  • free describes RAM and swap, with available memory distinct from unused memory.
  • df describes filesystem capacity; du measures 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.

  • On Ubuntu: man ps, man top, man free, man df, and man du.
  • Ubuntu manuals: top, free, and ps.
  • GNU Coreutils: df and du.