Skip to content

Practice: Processes and System Information

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 teammate asks whether a quiet command is stuck, whether its directory is consuming storage, and whether stopping it removes its temporary data. A process name and a single resource total cannot answer those questions. Your handoff needs separate observations and a tested reset.

This practice combines B13.1–B13.4. Use the lessons and manuals as needed. Collect evidence about your own bounded workloads, then explain what each observation establishes.

Finish Jobs and background work and the earlier lessons’ resets. Work in the same interactive Bash terminal throughout, from ~/lab in the B04 setup. Begin with no other jobs in this shell so the solution’s job selections are unambiguous. Reserve disposable ~/lab/b13 for the practice files.

Your PIDs, parent PIDs, job numbers, times, CPU figures, memory figures, filesystem sizes, and directory allocation will differ. The capture is a lab container: it has few processes, PID 1 is the Python capture program rather than systemd, and / is an overlay filesystem. Memory and capacity figures describe the Docker Desktop VM’s environment rather than a physical machine. Report relationships and units instead of trying to reproduce totals.

Reach these six goals:

  1. Start two harmless waiting instances with different durations, 180 and 240 seconds. Save their PIDs and prove they have separate identifiers and the same parent shell. Distinguish a waiting process state from completion.
  2. Inspect one saved instance with both a snapshot and interactive top. Identify its state and CPU activity. Report available memory and filesystem capacity separately, including their units and the container limitation.
  3. Create one 32 KiB file under the disposable directory using bounded input. Measure its allocated usage and the directory total. Explain why neither measurement replaces the filesystem capacity report.
  4. Bring the second job forward, suspend it, inspect its stopped state, resume it in the background, then bring it forward again and interrupt it. End the first wait with TERM. Establish that neither saved process remains.
  5. Recreate B13.3’s cooperative worker and input pipe. Prove its temporary file exists, request TERM, wait for completion, and prove the file is gone. Explain what KILL would have prevented, using B13.3’s separate KILL experiment as evidence.
  6. Remove the practice file, worker script, input pipe, and empty directory. Establish that this shell’s job table is empty. Do not signal unrelated processes or remove pre-existing data.

Predict before goal 4: can the same process be listed as Stopped and still retain its identity for later continuation?

Run it, then compare with your guess

Yes. Suspension pauses execution without completing the process. Resuming that job continues its existing instance; it does not allocate a replacement PID.

  • The two sleeps have different PIDs and a shared PPID. Their S process state represents waiting, while Bash calls their continuing jobs Running.
  • A selected top task row corresponds to one saved PID. Its percentages describe activity and memory, not filesystem use. Available RAM comes from free; filesystem capacity comes from df.
  • The captured file uses 32K and its directory totals 36K. Filesystem allocation can differ on your machine. Preserve the units and distinguish file contents from directory overhead.
  • A stopped-job notice follows Ctrl+Z. A jobs listing establishes suspension before background continuation. After fg and Ctrl+C, that wait ends. The other saved wait ends after TERM and wait.
  • The cooperative worker’s TERM message and an independent absence test establish cleanup. KILL would end execution without running its trap; closing descriptors would not automatically remove its temporary file.
  • Final process checks find neither sleep, the worker has completed, the directory is removed, and jobs has no entries.
Hint for identities and units

Save $! immediately after each background launch. Choose a few ps fields with -o, and select the saved PIDs with -p. Free, df, and du answer three different questions. State the unit beside every reported size.

Hint for the job transition

Use jobs to identify the second wait before selecting it. A job specification such as %2 is local to the current shell. jobs -l adds process identifiers, so you can connect a job number with the PID you saved earlier.

Hint for cleanup evidence

Sending TERM is the request; wait collects completion. Check the worker’s message and the temporary pathname separately. Remove the input channel only after the worker ends.

Solution

Start bounded instances and inspect resources.

Terminal window
sleep 180 & first=$!
sleep 240 & second=$!
ps -p "$first","$second" -o pid,ppid,stat,comm
free -h
df -h /
top -p "$first"

Quit top with q or Ctrl+C; this recording uses Ctrl+C after one initial interactive screen. The screen refreshes in place in a terminal; the replay preserves the initial screen rather than simulating live refreshes.

Identify two children and inspect resources
learner@rootvolt:~/lab$ sleep 180 & first=$![1] 19learner@rootvolt:~/lab$ sleep 240 & second=$![2] 20learner@rootvolt:~/lab$ ps -p "$first","$second" -o pid,ppid,stat,comm    PID    PPID STAT COMMAND
     19      11 S    sleep
     20      11 S    sleeplearner@rootvolt:~/lab$ free -h               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       876Mi       6.4Gi       3.8Mi       534Mi       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$ top -p "$first"top - 12:41:48 up  1:55,  0 user,  load average: 0.04, 0.06, 0.07
Tasks:   1 total,   0 running,   1 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st 
MiB Mem :   7790.7 total,   6525.9 free,    882.5 used,    534.4 buff/cache     
MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   6908.2 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND  
     19 learner   20   0    5696   2204   2096 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. Two captured sleep instances share a parent, and the solution inspects memory, filesystem capacity, and one selected interactive top row.
Steps (19)
  1. Type sleep 180 & first=$!
  2. Press Enter
  3. Output: [1] 19
  4. Type sleep 240 & second=$!
  5. Press Enter
  6. Output: [2] 20
  7. Type ps -p "$first","$second" -o pid,ppid,stat,comm
  8. Press Enter
  9. Output: PID PPID STAT COMMAND 19 11 S sleep 20 11 S sleep
  10. Type free -h
  11. Press Enter
  12. Output: total used free shared buff/cache available Mem: 7.6Gi 876Mi 6.4Gi 3.8Mi 534Mi 6.8Gi Swap: 2.0Gi 0B 2.0Gi
  13. Type df -h /
  14. Press Enter
  15. Output: Filesystem Size Used Avail Use% Mounted on overlay 1007G 3.3G 953G 1% /
  16. Type top -p "$first"
  17. Press Enter
  18. Output: top - 12:41:48 up 1:55, 0 user, load average: 0.04, 0.06, 0.07 Tasks: 1 total, 0 running, 1 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 7790.7 total, 6525.9 free, 882.5 used, 534.4 buff/cache MiB Swap: 2048.0 total, 2048.0 free, 0.0 used. 6908.2 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 19 learner 20 0 5696 2204 2096 S 0.0 0.0 0:00.00 sleep
  19. Press Ctrl + C

The captured instances are PIDs 19 and 20 with PPID 11. Both are waiting, not ended. Top’s selected task is the first sleep. The free report’s available field (6.8Gi here) and df’s Avail field (953G here) have different meanings even when both are sizes. The latter describes the container’s overlay filesystem.

Create and measure bounded storage.

Terminal window
mkdir -p ~/lab/b13
head -c 32768 /dev/zero > ~/lab/b13/note.bin
du -sh ~/lab/b13
du -h ~/lab/b13/note.bin
Measure a bounded practice file
learner@rootvolt:~/lab$ mkdir -p ~/lab/b13learner@rootvolt:~/lab$ head -c 32768 /dev/zero > ~/lab/b13/note.binlearner@rootvolt:~/lab$ du -sh ~/lab/b1336K	/home/learner/lab/b13learner@rootvolt:~/lab$ du -h ~/lab/b13/note.bin32K	/home/learner/lab/b13/note.binlearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. A 32 KiB file occupies 32K here, while its directory totals 36K with directory allocation included.
Steps (10)
  1. Type mkdir -p ~/lab/b13
  2. Press Enter
  3. Type head -c 32768 /dev/zero > ~/lab/b13/note.bin
  4. Press Enter
  5. Type du -sh ~/lab/b13
  6. Press Enter
  7. Output: 36K /home/learner/lab/b13
  8. Type du -h ~/lab/b13/note.bin
  9. Press Enter
  10. Output: 32K /home/learner/lab/b13/note.bin

Head limits the zero-byte source to 32,768 bytes. Du reports allocated usage, while df reports capacity of the containing filesystem. Your allocation may differ; this exercise creates no sparse file.

Select and suspend the second job.

Terminal window
jobs
fg %2

Confirm that job 2 is your 240-second sleep before selecting it. In the foreground, press Ctrl+Z, then run:

Terminal window
jobs -l
bg %2
jobs
fg

Press Ctrl+C when the second sleep is foreground again. The default fg selects the current job, which is the second wait in this sequence. The explicit jobs calls let you verify that selection instead of assuming the number is always correct.

Terminal window
kill "$first"; wait "$first"
ps -p "$first","$second" -o pid,comm
Suspend and resume the second instance
learner@rootvolt:~/lab$ fg %2sleep 240^Z[2]+  Stopped                 sleep 240learner@rootvolt:~/lab$ jobs -l[1]-    19 Running                 sleep 180 &
[2]+    20 Stopped                 sleep 240learner@rootvolt:~/lab$ bg %2[2]+ sleep 240 &learner@rootvolt:~/lab$ fgsleep 240^Clearner@rootvolt:~/lab$ kill "$first"; wait "$first"[1]+  Terminated              sleep 180learner@rootvolt:~/lab$ ps -p "$first","$second" -o pid,comm    PID COMMANDlearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. Selected steps preserve the second job's Stopped notice, its PID-bearing jobs listing, background continuation, foreground interruption, and final absence of both sleeps.
Steps (21)
  1. Type fg %2
  2. Press Enter
  3. Output: sleep 240
  4. Press Ctrl + Z
  5. Output: [2]+ Stopped sleep 240
  6. Type jobs -l
  7. Press Enter
  8. Output: [1]- 19 Running sleep 180 & [2]+ 20 Stopped sleep 240
  9. Type bg %2
  10. Press Enter
  11. Output: [2]+ sleep 240 &
  12. Type fg
  13. Press Enter
  14. Output: sleep 240
  15. Press Ctrl + C
  16. Type kill "$first"; wait "$first"
  17. Press Enter
  18. Output: [1]+ Terminated sleep 180
  19. Type ps -p "$first","$second" -o pid,comm
  20. Press Enter
  21. Output: PID COMMAND

The full capture also contains the jobs listings before fg and after bg. This shorter replay selects the PID-bearing stopped listing. The job retains PID 20 while suspended; bg resumes it. Ctrl+C ends that job. The first sleep instead ends with TERM, reported as Terminated during wait. The final ps prints only its header and returns 1.

Recreate the cooperative worker and request cleanup.

Terminal window
mkfifo ~/lab/b13/inbox

Create ~/lab/b13/cooperative.sh in your editor with the same supplied worker from B13.3:

Terminal window
file="$HOME/lab/b13/work.tmp"
exec 3<> "$HOME/lab/b13/inbox"
trap 'rm "$file"; printf "TERM: removed work.tmp\n"; exit 0' TERM
printf 'temporary data\n' > "$file"
read -r -t 300 -u 3
rm "$file"

The named pipe supplies a waiting input channel, descriptor 3 holds it open, and the trap removes only this worker’s temporary file. No helper process is needed. Run the comparison before its 300-second wait ends.

Terminal window
bash ~/lab/b13/cooperative.sh & process=$!
ls ~/lab/b13/work.tmp
kill "$process"; wait "$process"
test ! -e ~/lab/b13/work.tmp && printf 'Removed\n'
Request cooperative cleanup
learner@rootvolt:~/lab$ bash ~/lab/b13/cooperative.sh & process=$![1] 31learner@rootvolt:~/lab$ ls ~/lab/b13/work.tmp/home/learner/lab/b13/work.tmplearner@rootvolt:~/lab$ kill "$process"; wait "$process"TERM: removed work.tmp
[1]+  Done                    bash ~/lab/b13/cooperative.shlearner@rootvolt:~/lab$ test ! -e ~/lab/b13/work.tmp && printf 'Removed\n'Removedlearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. The worker creates work.tmp, handles TERM with its cleanup message, and passes the independent file-absence test.
Steps (12)
  1. Type bash ~/lab/b13/cooperative.sh & process=$!
  2. Press Enter
  3. Output: [1] 31
  4. Type ls ~/lab/b13/work.tmp
  5. Press Enter
  6. Output: /home/learner/lab/b13/work.tmp
  7. Type kill "$process"; wait "$process"
  8. Press Enter
  9. Output: TERM: removed work.tmp [1]+ Done bash ~/lab/b13/cooperative.sh
  10. Type test ! -e ~/lab/b13/work.tmp && printf 'Removed\n'
  11. Press Enter
  12. Output: Removed

Bash reports Done because the handler exits 0. B13.3’s KILL run instead reported Killed and left the file readable. In both paths the kernel closes descriptors, but it does not automatically delete named files. This practice requests the cooperative path; it does not repeat forceful termination.

Reset and check the shell’s final state.

Terminal window
cd ~/lab/b13
rm note.bin inbox cooperative.sh
cd ..
rmdir ~/lab/b13
jobs
unset first second process
Verify the final reset
learner@rootvolt:~/lab$ cd ~/lab/b13learner@rootvolt:~/lab/b13$ rm note.bin inbox cooperative.shlearner@rootvolt:~/lab/b13$ cd ..learner@rootvolt:~/lab$ rmdir ~/lab/b13learner@rootvolt:~/lab$ unset first second processlearner@rootvolt:~/lab$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. The solution removes the known practice paths and their empty directory, then clears its saved shell variables.
Steps (10)
  1. Type cd ~/lab/b13
  2. Press Enter
  3. Type rm note.bin inbox cooperative.sh
  4. Press Enter
  5. Type cd ..
  6. Press Enter
  7. Type rmdir ~/lab/b13
  8. Press Enter
  9. Type unset first second process
  10. Press Enter

The full capture’s final jobs call prints no entries. Both sleeps are already absent, and wait collected the worker’s successful completion. Successful rmdir establishes that the practice directory is empty and removed. No unrelated processes or paths are changed.

Answer before opening each explanation.

1. Why can two rows named sleep have the same PPID and different PIDs?

Answer

They are separate instances launched by one parent shell. The program name describes what runs, PID identifies an instance, and PPID identifies its parent.

2. How can a job be Running while its process state is S?

Answer

Bash’s Running means the job continues rather than being suspended. Process state S means interruptible sleep, waiting for an event. A continuing job need not consume CPU continuously.

3. Which report answers RAM availability, filesystem capacity, and directory usage?

Answer

Free reports memory, including available RAM. Df describes the containing filesystem’s capacity. Du estimates allocated usage of selected files and directories. Keep units and container scope attached to the observations.

4. What changes when bg resumes a stopped job?

Answer

The existing instance resumes execution in the background. Its identity remains; it is not restarted. Fg brings it to the foreground and can resume it there too.

5. Why does successful signal delivery not establish file cleanup?

Answer

It establishes that a signal was sent, not which handler ran or whether cleanup completed. Wait for completion, inspect application evidence, and check the pathname. KILL cannot run a user-space trap, although the kernel still closes descriptors.

6. Why is an empty jobs listing in another terminal insufficient reset evidence?

Answer

Each shell tracks its own jobs. Check the shell that started the work, verify saved process identities, and remove only the exercise’s files after its workers finish.

Goal 6 and the solution’s final commands are the recorded reset. They follow completed process checks and TERM cleanup, remove only the known practice files and input pipe, and remove the empty directory. If a job remains suspended, identify your own practice wait with jobs, resume it in the foreground, and interrupt it before finishing the reset.

  • Collect separate evidence for identity, process activity, memory, and storage.
  • Distinguish a suspended job from a continuing wait and from an ended process.
  • Request cooperative cleanup before considering forceful termination.
  • Verify process completion and pathname removal as separate reset outcomes.

Next, Network vocabulary for Linux users introduces the parts of a connection.

  • On Ubuntu: man ps, man top, man free, man df, man du, and man 7 signal.
  • In Bash: help jobs, help fg, help bg, help kill, and help wait.
  • Ubuntu Bash manual and signal manual.