Exercises — OS roles — resource management, hardware abstraction, protection
Level 1 — Recognition
L1·1 — Name the role
For each capability, say which of the three roles — Resource management, Abstraction, Protection — it belongs to:
(a) Giving each process a 10 ms turn on the CPU.
(b) Letting you call read(fd, buf, n) without knowing if the disk is an SSD or HDD.
(c) Killing a process with a segmentation fault when it touches memory it doesn't own.
(d) Deciding which process gets the next free chunk of RAM.
Recall Solution
(a) Resource management — the CPU is time-multiplexed; taking turns is scheduling.
(b) Abstraction — the read interface hides device-specific details behind one uniform contract.
(c) Protection — the MMU + OS stop a process from reaching resources it isn't permitted to.
(d) Resource management — RAM is space-multiplexed; handing out slices is allocation.
Mnemonic check: "The OS shares (R), hides (A), guards (P)."
L1·2 — True or False
(a) On a single CPU core, the OS runs ten programs literally simultaneously. (b) A user-mode program can disable the timer interrupt whenever it likes. (c) Swapping an HDD for an SSD forces you to rewrite your application code.
Recall Solution
(a) False. On one core it is fast switching (time-slicing → concurrency), not true parallelism. True parallelism needs multiple cores.
(b) False. "Set timer" is a privileged instruction. Attempted in user mode, the CPU raises a trap and the OS regains control.
(c) False. The open/read/write system-call contract is unchanged; only the device driver behind it changes. That is the whole point of abstraction.
Level 2 — Application
L2·1 — Utilization for one value
A process waits for I/O of the time. Compute CPU utilization for processes.
Recall Solution
Use with .
- : → 50%.
- : → 75%.
- : → 87.5%.
What it looks like: each extra process cuts the idle probability in half. Idle goes — see the shrinking gap in the figure below.

L2·2 — Higher I/O wait
Now (very I/O-heavy jobs). How many processes are needed to push above 0.90?
Recall Solution
We need , i.e. . Test values:
- : → (just short).
- : → (over 0.90 ✓).
So processes is the smallest count that clears 90%.
Why so many? With each process is idle 80% of the time; you need a big crowd so that at every instant someone is ready to run.
Level 3 — Analysis
L3·1 — Why does the segfault protect B?
Process A executes mov rax, [addr_in_B], trying to read a memory address that belongs to process B. Trace every step and state at which step B is guaranteed safe, and which layer (hardware vs OS) does each part.
Recall Solution
- A issues the load. The CPU hands
addr_in_Bto the MMU (hardware). - The MMU looks the address up in A's page table — not B's. Each process has its own table; A's table has no valid mapping for B's memory.
- Lookup fails → MMU raises a page fault (hardware detects the violation). B is already safe here: the read never reaches physical memory.
- The fault traps into kernel mode. The OS inspects it, sees an illegal access, and terminates A with SIGSEGV (policy — the OS decides what to do).
Split of labour: hardware enforces (the MMU physically blocks and traps), the OS decides policy (kill A, leave B running). Neither alone suffices — software checks could be skipped by malware, so the CPU/MMU backs the referee up.
L3·2 — The interlock question
The parent note claims "resource management depends on protection." Give the precise mechanism, and explain what would break if protection did not exist.
Recall Solution
Mechanism: Scheduling relies on the timer interrupt to snatch the CPU back after a process's time slice. "Set/disable timer" is a privileged instruction, blocked in user mode by dual-mode operation (a mode bit in the CPU). Without protection: a user process could disable the timer interrupt. Then no interrupt fires, the OS never regains control, and that process hogs the CPU forever (a spin-loop would freeze the machine). Fair time-sharing collapses. Conclusion: protection is the precondition that makes preemptive scheduling possible — you cannot enforce turns if a player can pocket the referee's whistle.
Level 4 — Synthesis
L4·1 — Trace a single read() through all three roles
You run read(fd, buf, 100) on a file. Walk the call and label where each of the three roles (R, A, P) shows up.
Recall Solution
readis a system call → executes a trap instruction → CPU switches user→kernel mode. (P: the protected gate — the only legal door into the kernel.)- The OS validates
fdand thatbuflies in your address space. (P: isolation check.) - The OS treats the disk as a file and asks the file system for the right blocks; you never see sectors or flash pages. (A: uniform interface over messy hardware.)
- The data isn't ready yet (disk is slow), so the OS blocks your process and schedules another one to keep the CPU busy. (R: time-multiplexing during I/O wait — exactly the effect.)
- When the disk finishes, an interrupt fires, the OS copies the bytes into
buf, and marks you runnable again. (R again + P: the copy is done by the trusted kernel.)
One call, all three roles. That's why the note says they interlock: abstraction is delivered through the protected gate, and the wait is filled by resource management.
L4·2 — Design reasoning
A junior engineer proposes: "To make things faster, let apps talk directly to the disk controller registers, skipping the OS." Give two things that break, one per remaining role.
Recall Solution
- Protection breaks: direct controller access is a privileged operation. Allowing it means any app can issue raw disk commands — reading or overwriting another program's (or the OS's) files. Isolation is gone.
- Abstraction breaks: the app now codes to this exact controller. Swap the disk model and the app stops working — no portability. Every app would need per-device code.
- (Bonus, Resource management) two apps hitting the controller at once with no referee → interleaved commands corrupt each other's transfers.
Verdict: the tiny speed gain isn't worth losing all three guarantees. The system-call detour is the safety.
Level 5 — Mastery
L5·1 — Marginal benefit of one more process
Using with , compute the extra utilization gained by going from to , and from to . What does the shrinking gain tell an OS designer about how many jobs to load?
Recall Solution
The gain of adding one process is . With , :
- : → +16 percentage points.
- : → +2.7 points.
Diminishing returns: each added job helps less than the last (the factor decays geometrically). See the flattening curve in the figure.
Design lesson: don't cram in unlimited processes. Beyond a point the utilization gain is tiny while each extra process still costs RAM and context-switch time — the OS must balance against memory pressure. This is why schedulers cap the degree of multiprogramming.

L5·2 — Two-mix reasoning
You have 4 memory slots. Job type X waits (heavy I/O); job type Y waits (CPU-bound). Assuming each slot holds one independent job, compare utilization for 4 X-jobs vs 4 Y-jobs, then explain which mix better justifies multiprogramming.
Recall Solution
With independent jobs, idle probability is the product of each job's wait probability. For a uniform batch of identical jobs this is .
- 4 X-jobs: → about 34.4%.
- 4 Y-jobs: → about 99.2%.
Reading it: CPU-bound Y-jobs already keep the CPU near-saturated with just 4 of them. The heavy-I/O X-jobs leave the CPU 65.6% idle even at — they need far more concurrency to fill the gaps.
Which justifies multiprogramming? The X (I/O-heavy) mix: multiprogramming's whole payoff is filling I/O-wait gaps, and X has enormous gaps. Y is already busy, so extra jobs add little. The economic argument for OS resource management is strongest exactly for I/O-bound workloads.
Recall Self-test summary (cover the answers)
Three roles ::: Resource management, Abstraction, Protection — "RAP". Utilization formula ::: , idle when all jobs wait. Gain of one more process ::: — shrinks geometrically (diminishing returns). Why protection enables scheduling ::: the timer interrupt is privileged; apps can't disable it, so preemption always works. The only legal user→kernel path ::: the system call / trap.
Related vault topics: CPU Scheduling, Virtual Memory and Paging, System Calls and Traps, Kernel vs User Mode, Interrupts and the Timer, Processes and Threads, Device Drivers and I/O.