The Big Picture: Four Jobs
Section 1 said the OS manages and simplifies. Now let's break that into four core jobs. Almost everything an OS does fits under one of them.
┌──────────────────────────────────────────────────────────┐
│ THE OPERATING SYSTEM │
├────────────────┬──────────────┬────────────┬─────────────┤
│ 1. SHARING │ 2. HIDING │ 3. PROTECT │ 4. JUGGLE │
│ (allocation) │ (abstraction)│ (security) │ (coordinate)│
├────────────────┴──────────────┴────────────┴─────────────┤
│ CPU RAM Disk Network Devices │
└──────────────────────────────────────────────────────────┘
Think of a restaurant. The manager shares the tables and the kitchen, hides the kitchen mess behind a simple menu, protects guests from trouble, and coordinates many orders at once. The OS does the same for programs.
2.1 Resource Allocation (Sharing Hardware)
What it is: Resource allocation means deciding which program gets which part of the hardware, and for how long. A resource is anything limited: CPU time, memory, disk space, network speed.
Two ways to share:
| Way | What it means | Example |
|---|---|---|
| Time sharing | Programs take turns, each for a very short moment | The CPU: program A runs for a few milliseconds, then B, then C... |
| Space sharing | The resource is cut into pieces, each program gets its own piece at the same time | RAM and disk: A gets these pages, B gets those |
Time sharing is the reason your PC seems to run everything at once. A CPU core runs one thread at a time, but it switches so fast (hundreds of times a second) that you cannot tell. Think of one chef cooking five dishes by stirring each pot for a few seconds in turn.
One CPU core, time-sliced:
time ─► | A | B | C | A | B | C | A | B | C |
The OS must be fair and smart. It balances three goals that can fight each other:
| Goal | Meaning |
|---|---|
| Fairness | No program is starved forever |
| Efficiency | Hardware is never left idle when there is work |
| Priority | Important work (your mouse cursor, music) goes first |
On Windows: Open Task Manager → Performance. You see CPU, Memory, Disk and Ethernet or Wi-Fi graphs. Each graph is a resource the OS is sharing out. The Details tab lets you right-click a process and set its priority (for example, Below normal). That is you asking the OS to change its sharing decision.
2.2 Abstraction (Hide Complexity)
What it is: Abstraction means hiding hard details behind a simple view. The OS builds a ladder of abstractions, one on top of another.
| Hardware reality | OS abstraction | What the programmer sees |
|---|---|---|
| Magnetic spots or flash cells | File | open("notes.txt") |
| Physical RAM chips | Address space (virtual memory) | "I have my own big, empty memory" |
| CPU cores | Process / thread | "My program runs on its own" |
| Network card and radio | Socket | "Send these bytes to that address" |
| Keyboard, mouse, touch | Input events | "The user pressed A" |
| Graphics chip | Window / drawing surface | "Draw here" |
Why does this matter? Three reasons:
- Simplicity. A programmer writes
read a file, not "send command 0x25 to the disk controller". - Portability. The same program runs on any PC, whatever its hardware.
- Safety. The OS checks every request, so a program cannot do something silly directly to the hardware.
Example: "Open a web page" in layers.
Browser: "Get me this web page"
│
OS network: splits data into packets, picks a connection
│
Driver: knows YOUR Wi-Fi chip's exact commands
│
Hardware: radio waves leave the antenna
Each layer only talks to the layer next to it. A layer can be replaced without the others noticing.
2.3 Security (Isolation and Protection)
What it is: The OS keeps programs and users apart and keeps the system safe. It must stop one program from spying on, damaging or crashing another, or the OS itself.
The OS uses these tools, each explained fully in Section 6:
| Tool | What it protects |
|---|---|
| Privilege rings (kernel mode and user mode) | Only trusted OS code can touch hardware directly |
| Private address spaces | A program cannot see another program's memory |
| Permissions on files | Only allowed users can read or change a file |
| Quotas (limits) | No program can use up all the resources |
Remember Chapter 2: the CPU itself has privilege rings. The OS uses that hardware feature, so security is not only software. The CPU enforces it.
An everyday picture: a hotel. Guests (programs) get a room key (permission) that opens only their own room. The staff (the kernel) have a master key. Guests cannot make a copy of the master key.
2.4 Coordination (Many Apps at Once)
What it is: Coordination means making many programs live together smoothly. The OS gives them ways to wait for each other, share information, and not trip over one another.
What the OS coordinates:
| Need | OS tool | Example |
|---|---|---|
| Programs trade data | Inter-process communication (IPC), such as pipes and shared memory | A browser sends a page to its own plug-in process |
| Two threads must not change the same data together | Locks (also called mutexes) | Two threads adding to one bank balance |
| A program must wait for slow hardware | Blocking and wake-up | A program waits for the disk and sleeps meanwhile |
| Events | Signals and messages | "The user closed the window" |
| Keep the order of disk work | Queues | Many programs writing to one disk |
Why locks matter: Imagine two cashiers both reading "balance = 100", each adding 50, and each writing back 150. The balance should be 200! A lock makes the second cashier wait until the first has finished. This kind of bug is called a race condition, and the OS gives programmers the tools to avoid it.
Waiting is clever. When a program asks for the disk, the OS does not make the CPU stare at the disk. It puts the program to sleep, runs something else, and wakes the program when the disk interrupts (Chapter 4, Section 3) to say "data ready". That one trick is the reason a PC stays responsive during a big file copy.
Summary
| Topic | Remember this |
|---|---|
| Resource allocation | The OS shares CPU, RAM, disk and network by time sharing and space sharing |
| Abstraction | Files, processes, virtual memory and sockets hide the real hardware |
| Security | Rings, private memory, permissions and quotas keep programs apart |
| Coordination | IPC, locks and sleep/wake let many programs cooperate |
| The pattern | Share, hide, protect, coordinate: the four jobs behind everything else in this chapter |