Practice: Processes and System Information
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.
Before you start
Section titled “Before you start”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.
Your task
Section titled “Your task”Reach these six goals:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Expected evidence
Section titled “Expected evidence”- The two sleeps have different PIDs and a shared PPID. Their
Sprocess 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
32Kand its directory totals36K. 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
Section titled “Solution”Solution
Start bounded instances and inspect resources.
sleep 180 & first=$!sleep 240 & second=$!ps -p "$first","$second" -o pid,ppid,stat,commfree -hdf -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.
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$ Steps (19)
- Type
sleep 180 & first=$! - Press Enter
- Output:
[1] 19 - Type
sleep 240 & second=$! - Press Enter
- Output:
[2] 20 - Type
ps -p "$first","$second" -o pid,ppid,stat,comm - Press Enter
- Output:
PID PPID STAT COMMAND 19 11 S sleep 20 11 S sleep - Type
free -h - Press Enter
- 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 - Type
df -h / - Press Enter
- Output:
Filesystem Size Used Avail Use% Mounted on overlay 1007G 3.3G 953G 1% / - Type
top -p "$first" - Press Enter
- 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 - 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.
mkdir -p ~/lab/b13head -c 32768 /dev/zero > ~/lab/b13/note.bindu -sh ~/lab/b13du -h ~/lab/b13/note.binlearner@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$ Steps (10)
- Type
mkdir -p ~/lab/b13 - Press Enter
- Type
head -c 32768 /dev/zero > ~/lab/b13/note.bin - Press Enter
- Type
du -sh ~/lab/b13 - Press Enter
- Output:
36K /home/learner/lab/b13 - Type
du -h ~/lab/b13/note.bin - Press Enter
- 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.
jobsfg %2Confirm that job 2 is your 240-second sleep before selecting it. In the foreground, press Ctrl+Z, then run:
jobs -lbg %2jobsfgPress 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.
kill "$first"; wait "$first"ps -p "$first","$second" -o pid,commlearner@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$ Steps (21)
- Type
fg %2 - Press Enter
- Output:
sleep 240 - Press Ctrl + Z
- Output:
[2]+ Stopped sleep 240 - Type
jobs -l - Press Enter
- Output:
[1]- 19 Running sleep 180 & [2]+ 20 Stopped sleep 240 - Type
bg %2 - Press Enter
- Output:
[2]+ sleep 240 & - Type
fg - Press Enter
- Output:
sleep 240 - Press Ctrl + C
- Type
kill "$first"; wait "$first" - Press Enter
- Output:
[1]+ Terminated sleep 180 - Type
ps -p "$first","$second" -o pid,comm - Press Enter
- 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.
mkfifo ~/lab/b13/inboxCreate ~/lab/b13/cooperative.sh in your editor with the same supplied worker from B13.3:
file="$HOME/lab/b13/work.tmp"exec 3<> "$HOME/lab/b13/inbox"trap 'rm "$file"; printf "TERM: removed work.tmp\n"; exit 0' TERMprintf 'temporary data\n' > "$file"read -r -t 300 -u 3rm "$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.
bash ~/lab/b13/cooperative.sh & process=$!ls ~/lab/b13/work.tmpkill "$process"; wait "$process"test ! -e ~/lab/b13/work.tmp && printf 'Removed\n'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$ Steps (12)
- Type
bash ~/lab/b13/cooperative.sh & process=$! - Press Enter
- Output:
[1] 31 - Type
ls ~/lab/b13/work.tmp - Press Enter
- Output:
/home/learner/lab/b13/work.tmp - Type
kill "$process"; wait "$process" - Press Enter
- Output:
TERM: removed work.tmp [1]+ Done bash ~/lab/b13/cooperative.sh - Type
test ! -e ~/lab/b13/work.tmp && printf 'Removed\n' - Press Enter
- 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.
cd ~/lab/b13rm note.bin inbox cooperative.shcd ..rmdir ~/lab/b13jobsunset first second processlearner@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$ Steps (10)
- Type
cd ~/lab/b13 - Press Enter
- Type
rm note.bin inbox cooperative.sh - Press Enter
- Type
cd .. - Press Enter
- Type
rmdir ~/lab/b13 - Press Enter
- Type
unset first second process - 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.
Recall check
Section titled “Recall check”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.
Reset this lesson
Section titled “Reset this lesson”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.
Further reading
Section titled “Further reading”- On Ubuntu:
man ps,man top,man free,man df,man du, andman 7 signal. - In Bash:
help jobs,help fg,help bg,help kill, andhelp wait. - Ubuntu Bash manual and signal manual.