1.1.13How Computers Work

Operating system role — resource manager, abstraction layer

2,150 words10 min readdifficulty · medium

WHAT is an Operating System?

The two pillars:

Role What it solves Example
Resource manager Many programs, limited hardware Scheduling CPU between Chrome & Spotify
Abstraction layer Hardware is messy & varies "Open a file" works on SSD, HDD, USB
Figure — Operating system role — resource manager, abstraction layer

WHY do we even need an OS?


HOW: Role 1 — Resource Manager

The OS controls four classes of resource. The trick everywhere is multiplexing: sharing one physical thing among many users in space or time.

CPU — time multiplexing (scheduling)

The OS gives each process a small time slice (quantum), then a hardware timer interrupt forces control back to the OS, which picks the next process. This creates the illusion of programs running simultaneously on a single core.

Memory — space + time multiplexing

The OS hands each process its own virtual address space and tracks which physical RAM frames are free.

Disk, devices, time

The OS arbitrates disk access, owns device drivers, and meters access (permissions) so one user can't trample another.


HOW: Role 2 — Abstraction Layer

The OS replaces physical nastiness with clean conceptual objects:

Raw hardware reality OS abstraction Program just says
Magnetic sectors / NAND blocks File / filesystem open("a.txt")
Physical RAM addresses, swapping Virtual memory / address space use any address
One CPU, registers, interrupts Process / thread "run my code"
Voltage signals on a port Device file / driver API write(socket, ...)

Forecast-then-Verify

Recall Forecast before reading the answer

Q: You have a single CPU core. Programs are CPU-bound (almost no I/O, p0p \approx 0). Does running more programs improve CPU utilization? Predict, then check.

Verify: U=1pnU = 1 - p^n. With p0p \approx 0, U1U \approx 1 already with one program. Extra programs add no utilization gain (and add switching overhead). Multiprogramming only helps when pp is large (I/O-heavy). ✅


Common Mistakes (Steel-man + Fix)


Flashcards

What are the two core roles of an operating system?
Resource manager (share scarce hardware) and abstraction layer (hide hardware behind clean interfaces).
Define multiplexing and its two kinds.
Sharing one resource among many users; time multiplexing (take turns) and space multiplexing (split into simultaneous pieces).
Why does the CPU appear to run many programs at once on one core?
Time multiplexing — small time slices with timer interrupts switch processes faster than humans perceive.
What formula gives CPU utilization with n processes each idle fraction p in I/O?
U=1pnU = 1 - p^n, derived from probability all n wait at once being pnp^n.
What is a system call?
A controlled entry point for a program to request an OS service, switching user mode → kernel mode.
Why do we need user mode vs kernel mode?
So untrusted programs can request privileged actions without directly having privileges, giving protection.
Give the OS abstraction for raw disk sectors.
The file / filesystem.
Give the OS abstraction for physical RAM and CPU respectively.
Virtual memory/address space; and the process/thread.
Worst-case wait for a process in round-robin (n procs, quantum q)?
(n1)q(n-1)q.
When does multiprogramming NOT improve utilization?
When processes are CPU-bound (p ≈ 0); extra programs add overhead without raising U.

Recall Feynman: explain to a 12-year-old

A computer's brain (CPU) can really only do one tiny thing at a time, but you want music, games, and homework all going. The Operating System is like a super-fast teacher in a classroom: it lets one kid talk for a split second, then the next, so fast it looks like everyone talks together. It also keeps kids from grabbing each other's stuff (your game can't peek at your bank app). And it gives easy buttons — you say "save my file" and the teacher does all the boring machine work behind the curtain. So the OS = fair sharer + helpful curtain.

Connections

  • Processes and Threads — the CPU abstraction the OS schedules.
  • Virtual Memory — the RAM abstraction & space multiplexing.
  • System Calls and Kernel Mode — the user↔kernel boundary.
  • CPU Scheduling — algorithms behind time multiplexing.
  • File Systems — the disk abstraction.
  • Interrupts and the Fetch-Execute Cycle — how the timer returns control to the OS.
  • Device Drivers — hardware diversity hidden by the OS.

Concept Map

sits between

manages

does job 1

does job 2

hides messy diverse

shares scarce

uses technique

take turns

split pieces

applied to

forced back by

worst wait = n-1 times q

Operating System

Hardware

Application Programs

Resource Manager

Abstraction Layer

Multiplexing

Time Multiplexing

Space Multiplexing

CPU Scheduling

Timer Interrupt

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Operating System ko ek hostel ke manager ki tarah samjho. Computer ke andar CPU, RAM, disk sab limited hain, par tum ek saath Chrome, Spotify, aur code editor chalana chahte ho. Agar koi manager na ho to do programs ek hi RAM ya CPU pe ladai kar denge aur system crash ho jayega. Isliye OS ke do main kaam hain: ek resource manager (kaun, kab, kitna hardware use karega — yeh decide karna) aur doosra abstraction layer (hardware ki gandi details chhupa ke simple interface dena, jaise "file open karo").

Resource manager wala part multiplexing se chalta hai. Single core pe OS har program ko ek chhota sa time slice (jaise 10 ms) deta hai, phir timer interrupt se control wapas le leta hai aur agle program ko chance deta hai. Itni fast switching hoti hai ki humein lagta hai sab ek saath chal rahe hain — actually woh sirf illusion hai. Aur ek mast formula hai: U=1pnU = 1 - p^n, jahan pp matlab program ka I/O wait ka fraction. Iska matlab — agar programs zyada I/O karte hain (disk/network wait), to zyada programs chalane se CPU busy rehta hai, idle nahi baithta. Isliye OS itne saare programs juggle karta hai.

Abstraction wala part bhi utna hi zaroori hai. Tum code mein bas read() ya open() likhte ho — peeche OS hi disk ke sectors dhundhta hai, permission check karta hai, driver ko command bhejta hai. Yeh sab system call ke through hota hai, jahan program user mode se kernel mode mein jata hai. Yeh design protection deta hai: tumhara game tumhare bank app ki memory nahi padh sakta, kyunki OS use map hi nahi karta. Yaad rakhne ka tarika: OS = tumhare computer ka "MA"Manager aur Abstractor.

Test yourself — How Computers Work

Connections