OS roles — resource management, hardware abstraction, protection
WHY does an OS even exist?
WHY (first principles): Imagine a computer with NO OS. Every program must directly:
- Talk to the disk controller (different code for every disk model).
- Decide when to give the CPU to another program (but a buggy program never will).
- Read/write any memory address (so program A can scribble over program B).
This is unsafe, non-portable, and chaotic. The OS is the trusted referee that owns the hardware so applications don't have to.

Role 1 — Resource Management
WHAT it manages: CPU time, memory, storage, I/O devices, network bandwidth.
HOW (CPU example): The CPU can run only one instruction stream at a time per core. The OS gives each process a tiny time slice (e.g. 10 ms), then a hardware timer interrupt fires, control returns to the OS, and it picks the next process. Switching this fast creates the illusion that all programs run at once.
Role 2 — Hardware Abstraction
WHAT abstractions you already use:
| Physical reality | OS abstraction |
|---|---|
| Magnetic sectors / SSD flash blocks | File (open/read/write/close) |
| Physical RAM chips + paging | Virtual address space |
| CPU cores + timer | Process / thread |
| Network card registers | Socket |
HOW: Your code calls read(fd, buf, n). The OS translates this through the file system → block layer → device driver → controller registers. You never know if it was an SSD, HDD, or USB stick. Swap the disk, swap the driver — your program is unchanged. That's portability.
Role 3 — Protection (and Isolation)
WHY hardware help is required: Software alone can't enforce this — a malicious program could just skip the checks. So the CPU itself refuses privileged instructions in user mode and traps to the OS.
HOW it works (the mechanisms):
- Dual-mode operation: a mode bit in the CPU. Privileged instructions (set timer, do I/O, modify page tables) fault if attempted in user mode.
- Memory protection: the MMU checks every address against the process's page table. Out-of-bounds → page fault → OS kills the process (the classic segmentation fault).
- System calls: the only legal door into the kernel. The app sets up arguments, executes a
syscall/trap instruction, CPU switches to kernel mode, OS validates the request, does it, returns.
How the three roles interlock
Recall Feynman: explain to a 12-year-old
Imagine one PlayStation and ten kids who all want to play, and some of them are bullies. A fair referee (the OS) does three things:
- Takes turns (resource management): everyone gets 10 seconds, then the next kid — so fast it feels simultaneous. While one kid stares at the menu (I/O wait), the referee lets someone else play, so the console is never just sitting idle.
- Universal remote (abstraction): the kids press the same buttons whether it's a PS4 or PS5 or a TV with weird ports. The referee hides the wiring.
- Bodyguard (protection): if a kid tries to grab someone else's save file or hold the controller forever, the referee instantly takes it away. The kids physically can't break the rules because the console hardware backs the referee up. That referee is the operating system.
Flashcards
What are the three core roles of an OS?
Why does an OS need to do resource management?
CPU utilization formula for n processes each waiting fraction p of the time
Why does adding more I/O-bound processes raise CPU utilization?
What is hardware abstraction?
What hides device-specific details behind the OS's uniform interface?
What two CPU modes enable protection?
What is the only legal way for a user program to enter the kernel?
What hardware unit enforces memory protection on every access?
Why can't a user process disable the preemption timer?
True parallelism vs the concurrency illusion on one core?
Who sets protection policy vs who enforces the mechanism?
Connections
- Processes and Threads — the abstraction the scheduler manages.
- CPU Scheduling — the concrete algorithms of Role 1.
- Virtual Memory and Paging — abstraction + protection of RAM via the MMU.
- System Calls and Traps — the protected gate between user and kernel.
- Interrupts and the Timer — the mechanism that lets the OS reclaim the CPU.
- Device Drivers and I/O — where hardware abstraction is implemented.
- Kernel vs User Mode — the hardware basis of protection.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Socho ek hi computer hai aur usme bahut saare programs ek saath chalna chahte hain — aur ye programs ek dusre par bharosa nahi karte. Bas yahi ek tension se OS ke teen kaam nikalte hain. Pehla: resource management — CPU, RAM, disk limited hain, to OS sabko time-slice deke baari-baari chalata hai, itni fast ki lagta hai sab ek saath chal rahe hain. Jab ek program I/O ka wait kar raha ho, OS doosre ko CPU de deta hai, isliye CPU idle nahi baithta. Yahi reason hai ki zyada I/O-heavy programs load karne se CPU utilization badhta hai — formula .
Doosra kaam: hardware abstraction. Duniya mein hazaar tarah ke disk, GPU, network card hain. Agar har app ko har device ka code likhna pade to software banega hi nahi. To OS ek clean interface deta hai — file, process, socket, virtual memory — aur asli device ka mess driver ke peeche chhupa deta hai. Tum sirf open/read/write likhte ho, neeche HDD ho ya SSD, tumhe farak nahi padta. Yahi portability hai.
Teesra kaam: protection. CPU ke do mode hote hain — user mode (limited) aur kernel mode (full power, sirf OS). User program seedha hardware ko ya doosre program ki memory ko touch nahi kar sakta; uska sirf ek darwaaza hai — system call (trap). Memory ke har access ko MMU check karta hai page table se; galat address pe gaye to segmentation fault. Important baat: policy OS decide karta hai, par enforce hardware karta hai (mode bit + MMU). Isiliye koi rogue program OS ko ignore karke timer disable nahi kar sakta — aur isi wajah se Role 1 (sharing) tabhi possible hai jab Role 3 (protection) ho. Yaad rakho: RAP — Resource, Abstraction, Protection.