0 · Recall Warm-up
Answer from memory first. Answers are in the Answer Vault at the bottom.
- 32 address bits give how much memory? from Lesson 0.1.1
- Program vs process? from Lesson 0.1.1
1 · The Hook
If any program could switch off the timer, overwrite another program's memory or talk to the disk directly, one buggy app could crash the whole machine. So the CPU has two modes: a powerful kernel mode reserved for the operating system and a restricted user mode for everything else. GATE asks which instructions must be restricted, and how control moves between the two.
2 · Predict First
Try the questions first. Open when you are ready to check.
Which of these should an ordinary app NOT be allowed to do directly: (a) add two numbers, (b) switch off interrupts, (c) read the current time, (d) change the timer?
Make a guess in your head. The answer opens Section 3.
3 · Core Concept
Predict First — the answer
(b) and (d). Switching off interrupts or changing the timer would let one app take over the CPU forever. Adding numbers and reading the time are harmless.
In plain words
The operating system is the manager that shares the computer between programs and protects them from each other. The CPU has a switch: in kernel mode anything goes, in user mode dangerous instructions are blocked. Programs run in user mode; the OS kernel runs in kernel mode. Interrupts are the doorbell that hands control back to the OS.
1. What an operating system does
- Resource manager: shares the CPU, memory, disk and devices among processes.
- Abstraction: gives programs simple ideas (files, processes, virtual memory) instead of raw hardware.
- Protection: keeps processes from damaging each other or the OS.
The core part that is always in memory and runs in kernel mode is the kernel.
2. Two modes
A mode bit in the CPU says which mode is active.
- User mode: ordinary programs; privileged instructions are refused (attempting one causes a trap to the OS).
- Kernel mode (supervisor mode): the OS; every instruction is allowed.
- Privileged instructions (kernel mode only): I/O instructions, setting the timer, enabling/disabling interrupts, changing memory-management registers, halting the CPU, switching to kernel mode directly.
- Not privileged: arithmetic, reading the clock, and the special trap / system-call instruction that asks the OS for help (it must be usable from user mode, otherwise programs could never request anything).
3. Interrupts, traps and the timer
- Interrupt (from hardware): a device signals the CPU ("key pressed", "disk read finished"). The CPU saves what it was doing, switches to kernel mode and runs the OS's interrupt handler.
- Trap / exception (from software): caused by the running program: a system call, a division by zero, an illegal memory access.
- Timer interrupt: the OS sets a timer before giving the CPU to a process; when it fires, the OS gets control back. This is how one process is prevented from hogging the CPU.
4. Kinds of operating systems
| Kind | Idea |
|---|---|
| Batch | jobs run one after another, no interaction |
| Multiprogramming | several programs in memory; when one waits for I/O, the CPU runs another (keeps the CPU busy) |
| Time-sharing (multitasking) | switch between programs so quickly that each user feels it has the machine |
| Real-time | must meet deadlines (hard or soft) |
The degree of multiprogramming is the number of processes in memory at once.
4 · Visual
Control enters the kernel only through traps (system calls, errors) and interrupts; the kernel returns to user mode when done.
| Instruction | Privileged? |
|---|---|
| set the timer | yes |
| disable interrupts | yes |
| perform I/O directly | yes |
| change page-table / memory registers | yes |
| read the time of day | no |
| add, compare, jump | no |
| system-call (trap) instruction | no (it is how user programs enter the kernel) |
5 · Worked Examples
Example 1 Easy
In which mode does a word processor normally run?
Solution
User mode.
Example 2 Medium
Why must the "set timer" instruction be privileged?
Solution
A user program could otherwise set a huge timer (or none) and never give the CPU back.
Example 3 GATE
Which instruction must be executable in user mode: "disable interrupts" or "trap to the kernel"?
Solution
Trap to the kernel: it is the only way a user program can ask for OS services.
6 · GATE Traps
- The system-call (trap) instruction is not privileged, even though it leads into the kernel.
- Reading the clock is harmless; setting the timer is privileged.
- Interrupts come from devices; traps come from the running program.
- Multiprogramming ≠ multiprocessing (the latter means several CPUs).
7 · Memory Hook
"Dangerous instructions live in kernel mode; apps knock with a trap."
8 · Connect the Dots
A user program that needs a file or a new process must ask the kernel. The next lesson shows exactly how: system calls.
9 · Self-Test
GATE format. Try every question before opening the vault.
Q1 · MCQ · 1 mark(s) — Privileged instructions
Which instruction should be privileged?
- (A) Set the value of the timer
- (B) Add two registers
- (C) Read the time of day
- (D) Execute a system-call (trap) instruction
Q2 · MSQ · 2 mark(s) — Privileged set
Which of these must run only in kernel mode?
- (A) Read the system clock
- (B) Directly start a disk I/O operation
- (C) Change the memory-management (page-table) register
- (D) Disable all interrupts
Q3 · MCQ · 1 mark(s) — Interrupts
A keyboard key press reaches the OS as:
- (A) a system call
- (B) a hardware interrupt
- (C) a trap
- (D) a privileged instruction
Q4 · MCQ · 1 mark(s) — Timer
What lets the OS take the CPU back from a process that never makes a system call?
- (A) Virtual memory
- (B) The disk controller
- (C) The mode bit
- (D) The timer interrupt
Q5 · MCQ · 1 mark(s) — Multiprogramming
The main goal of multiprogramming is to:
- (A) keep the CPU busy while other programs wait for I/O
- (B) give each user a separate CPU
- (C) run real-time tasks
- (D) remove the need for an OS
10 · Rule Card
- OS = resource manager + abstraction + protection; kernel runs in kernel mode.
- Mode bit: user mode (restricted) vs kernel mode (all instructions).
- Privileged: I/O, set timer, enable/disable interrupts, memory-management registers, halt. Not privileged: arithmetic, read clock, trap/system-call instruction.
- Interrupt = from hardware; trap/exception = from the running program; timer interrupt returns control to the OS.
- Multiprogramming keeps the CPU busy; time-sharing switches fast for interaction.
11 · Concept Ledger
Unlocked in this lesson. From here on, these terms may be used.
operating system roleskerneluser mode and kernel modemode bitprivileged instructionshardware interruptstraps and exceptionsinterrupt handlertimer interruptbatch, multiprogramming, time-sharing and real-time systemsdegree of multiprogramming
12 · Answer Vault
Try the questions first. Open when you are ready to check.
🔐 Open the Answer Vault
Recall Warm-up
- 4 GB.
- A process is a program in execution.
Self-Test
Q1 Answer: (A) · 1 mark(s)
Otherwise a process could keep the CPU forever.
- (B) is wrong: Ordinary arithmetic.
- (C) is wrong: Harmless.
- (D) is wrong: User programs need it to request services.
Re-read: Lesson 0.1.2 — What an operating system does: kernel, user mode and kernel mode, interrupts
Q2 Answer: (B) (C) (D) · 2 mark(s)
Reading the clock cannot harm others.
- (A) is wrong: Not privileged.
Re-read: Lesson 0.1.2 — What an operating system does: kernel, user mode and kernel mode, interrupts
Q3 Answer: (B) · 1 mark(s)
Generated by a device.
- (A) is wrong: The program did not ask.
- (C) is wrong: Traps come from the running program.
- (D) is wrong: Not an instruction.
Re-read: Lesson 0.1.2 — What an operating system does: kernel, user mode and kernel mode, interrupts
Q4 Answer: (D) · 1 mark(s)
The timer fires and enters the kernel.
- (A) is wrong: About memory.
- (B) is wrong: Unrelated.
- (C) is wrong: Only says which mode is active.
Re-read: Lesson 0.1.2 — What an operating system does: kernel, user mode and kernel mode, interrupts
Q5 Answer: (A) · 1 mark(s)
Overlap computing with I/O waits.
- (B) is wrong: That is multiprocessing.
- (C) is wrong: Real-time is a different goal.
- (D) is wrong: It needs an OS.
Re-read: Lesson 0.1.2 — What an operating system does: kernel, user mode and kernel mode, interrupts