4.2.1 · D1Operating Systems

Foundations — OS roles — resource management, hardware abstraction, protection

2,820 words13 min readBack to topic

Before you can read the parent note OS Roles fluently, you need a small toolbox of words, pictures, and one probability formula. This page builds every single one from nothing, in an order where each item leans only on the ones before it. If a word below already feels obvious, good — read it anyway, because the parent note stacks these into arguments and a shaky floor cracks the whole tower.


0. The two physical things we start from

Everything in this chapter is a story about two nouns: the hardware and the program. Let's nail down exactly what each is with a picture before any fancy word appears.

Figure — OS roles — resource management, hardware abstraction, protection

Look at the figure: along the bottom sits one box labelled HARDWARE — the single physical machine, split into its parts (CPU, RAM, Disk, I/O). Floating above it are several separate process boxes (P1, P2, …), and every one of them points an arrow down at the same machine. That downward crowd of arrows onto a single box is the whole tension of this chapter drawn in one picture: many demanders, one supplier.

Why does the topic need this distinction? Because "share the machine" really means "let many processes (running things) use one set of hardware (physical things)." The whole tension lives in the gap between one hardware and many processes. You will meet processes again in depth in Processes and Threads.


1. The CPU, a core, an instruction, and "one at a time"

The single most important physical fact in the whole chapter:

Figure — OS roles — resource management, hardware abstraction, protection

Look at the figure: real time flows left to right, and at every vertical slice exactly one colored process is on the core. The illusion of "all at once" comes from the slices being tiny (about 10 milliseconds — a hundredth of a second). This slicing is CPU Scheduling.


2. Time-multiplexing vs space-multiplexing

The parent note says the OS "multiplexes" resources in two flavours. Multiplex is a scary word for a simple idea: make one thing serve many users. There are exactly two ways to do it.

Figure — OS roles — resource management, hardware abstraction, protection

Read the figure as two halves. On the left (time), the same one resource is handed to A, then B, then C in a row along time — you only ever hold it in turn. On the right (space), the one resource is sliced into stacked bands A, B, C that all exist at the same moment — everyone holds their piece continuously. The picture makes the difference physical: left = take turns with the whole thing; right = keep a piece of it forever.

Why the topic needs both words: "resource management" (Role 1) is nothing but choosing which kind of multiplexing fits which resource and doing it well. The CPU can't be cut in space (an instruction can't be half-run), so it must be shared in time. RAM naturally divides into byte-slices, so it's shared in space.


3. The symbols in the utilization formula

The parent note's one formula is . Three symbols hide in there. We define each in plain words, tie it to a picture, then say why it's needed.

Why probability at all, and not just algebra? Because we cannot predict the exact instant a process needs I/O — it depends on data, user typing, disk speed. When you can't predict an exact moment but you can say "how often on average," the right tool is probability: a number measuring "what fraction of the time." That is precisely the question the OS designer asks: "what fraction of the time is my expensive CPU wasted?"

Picture two coins. Each shows heads with probability . Both heads at once? — one quarter of the outcomes. Now stretch this: the CPU is idle only when process 1 is waiting AND process 2 is waiting ANDAND process is waiting. Multiply copies of :

CPU busy is just "not idle," and a probability plus its opposite always sum to (something either happens or it doesn't). So:

Covering the edge cases so no scenario surprises you:

  • : . No processes → CPU never busy. ✓
  • , : process never waits → . CPU always busy. ✓
  • : a process that waits forever. Then for any , so . Loading more useless processes helps nothing. ✓
  • with : shrinks toward , so climbs toward — but never reaches it. This is the mathematical reason multiprogramming has diminishing returns.
Figure — OS roles — resource management, hardware abstraction, protection

The figure plots up the vertical axis against along the horizontal axis, one curve per value of . Trace the pink curve: it passes through the very numbers in the example below — — and you can see each new process lift by a smaller step than the last, the curve bending flat as it crawls toward the dashed ceiling line at (the "never quite reached" edge case above). Steeper curves start lower (more waiting = more idle) but climb the same shape.

You'll see where these I/O waits truly come from in Device Drivers and I/O and Interrupts and the Timer.


4. Abstraction, interface, and the file

Why the topic needs it: Role 2 (hardware abstraction) is the act of the OS offering one interface (like the file) that hides thousands of different disks. The messy translation lives in a device driver, and the address-hiding trick behind memory is Virtual Memory and Paging.


5. The two modes and the gate

Figure — OS roles — resource management, hardware abstraction, protection

Read the figure as two rooms. The left blue box is USER mode, where apps live and privileged instructions are forbidden. The right pink box is KERNEL mode, where only the OS runs with full power. Between them stands one yellow arrow — the trap/syscall gate — and it is the only way across. There is deliberately no other opening in the wall: that single guarded door is the entire mechanism of protection in one drawing.

Why the topic needs this: Role 3 (protection) is impossible without hardware that physically refuses privileged instructions in user mode. Software checks alone could be skipped by a malicious program; a hardware fence cannot. This is also why an app can't switch off the CPU timer — disabling it is a privileged instruction, so the OS keeps its power to preempt.


Prerequisite map

Hardware CPU RAM disk

One core one stream

Program vs process

Time vs space multiplex

Role 1 Resource management

Probability and independence

U equals 1 minus p to the n

Interface and abstraction

Role 2 Hardware abstraction

User mode and kernel mode

Trap and system call

Role 3 Protection

Read it top-down: physical facts feed the multiplexing idea, which feeds resource management; probability feeds the utilization formula; interfaces feed abstraction; modes feed the trap gate, which feeds both protection and abstraction.


Equipment checklist

Cover the right side and answer out loud. If any stalls you, re-read that section before the parent note.

What is the difference between a program and a process?
A program is instructions sitting on disk (a recipe); a process is that program loaded and running with its own memory (the cooking).
What is a core, and how many instruction streams can it run at one instant?
A core is one execution unit inside the CPU (one worker, one pair of hands); it runs exactly one instruction stream at a time.
What does I/O mean and why does it matter here?
I/O = input/output, moving data between CPU and the outside world (disk, keyboard, network); it's slow, so a process doing I/O mostly waits — freeing the CPU for others.
What does it mean to preempt a process?
The OS forcibly takes the core away mid-run and hands it to another process, so no one can freeze everyone else out.
What is time-multiplexing vs space-multiplexing?
Time = give the whole resource to one user then pass it on (CPU); space = cut it into slices held at once (RAM, disk).
In , what do , , and each mean?
= probability one process is waiting for I/O; = number of loaded processes; = fraction of time the CPU is busy.
Why is the idle probability and not ?
CPU is idle only when all processes wait simultaneously; independent events multiply, giving .
What does equal and why does that make sense?
; with zero processes the CPU is idle all the time, so busy fraction .
What is an abstraction, in one sentence?
A simple invented idea (like a "file") that stands in for messy hardware so you don't deal with the mess.
What is an interface?
A fixed menu of allowed operations you can request without knowing how they're done inside.
What do user mode and kernel mode differ in?
Kernel mode allows every instruction (only the OS runs there); user mode forbids privileged instructions (apps run there).
What is the CPU timer and why is it privileged?
Hardware that counts down and interrupts the CPU to return control to the OS (ending each time slice); only the OS may set it, so apps can't disable preemption.
What is the only legal way for a user program to enter the kernel?
Through a trap / system call — the single controlled gate the OS guards.
Why can't a user program disable the CPU timer to hog the machine?
Disabling the timer is a privileged instruction; attempting it in user mode makes the hardware trap to the OS.