Chapter 2: Operating System Design and Implementation
Syllabus 9.2: Architecture, Kernel types, System Calls, Interrupts, Context Switching, Boot Process & Virtual Machines
Learning Objectives
After completing this chapter, you should be able to:
- Explain OS architecture
- Differentiate Monolithic Kernel and Microkernel
- Understand System Calls
- Explain Interrupts and Traps
- Describe Context Switching
- Explain the Boot Process
- Understand Virtual Machines
1. Operating System Architecture
OS architecture refers to the internal structure and organization of an operating system. It defines how components interact, how services are provided, and how hardware resources are managed.
| Basic Structure (Top to Bottom) |
|---|
| Users |
| ↓ Application Programs |
| ↓ Operating System |
| ↓ Hardware |
A modern OS contains: Kernel, Memory Manager, File Manager, Process Manager, Device Manager, Security Manager.
2. Kernel Architecture
The kernel is the most important component of the OS. It operates in two distinct modes:
Kernel Mode vs User Mode
| Mode | Access Level | Who Runs Here |
|---|---|---|
| Kernel Mode | Full hardware access, privileged instructions allowed | OS kernel |
| User Mode | Restricted access | Applications |
Why Two Modes? If every application had direct access to RAM and CPU, it would cause system crashes, security issues, and data corruption. The separation ensures stability and security.
| Flow |
|---|
| Applications (User Mode) ↓ System Call ↓ Kernel (Kernel Mode) ↓ Hardware |
3. Monolithic Architecture
All OS services run inside one large kernel. Everything executes in kernel space.
| Aspect | Detail |
|---|---|
| Services Included | File system, Device drivers, Memory manager, Process scheduler |
| Structure | Applications ↓ Monolithic Kernel ↓ Hardware |
| Advantage: Fast Performance | No communication overhead between components |
| Advantage: Efficient | Direct interaction among components |
| Disadvantage: Hard Maintenance | Large, complex code base |
| Disadvantage: Low Fault Isolation | One faulty driver may crash the whole OS |
| Examples | UNIX, Linux |
4. Microkernel Architecture
Only essential services remain inside the kernel. Other services run in user space.
| Aspect | Detail |
|---|---|
| Kernel Contains | Scheduling, Memory management, IPC (Interprocess Communication) |
| Structure | Applications ↓ User Services ↓ Microkernel ↓ Hardware |
| Advantage: Better Security | Smaller kernel attack surface |
| Advantage: Better Stability | Fault in one service will not crash the entire OS |
| Advantage: Easier Maintenance | Modular design |
| Disadvantage | Slower due to more communication required between components |
| Examples | MINIX, QNX |
Monolithic vs Microkernel
| Feature | Monolithic | Microkernel |
|---|---|---|
| Size | Large | Small |
| Speed | Faster | Slower |
| Security | Lower | Higher |
| Reliability | Lower | Higher |
| Maintenance | Difficult | Easier |
📌 Exam Point: Which architecture provides better fault isolation? → Microkernel
5. Layered Architecture
The OS is divided into layers. Each layer uses only the services of the layer directly below it.
| Layer | Component |
|---|---|
| Layer 5 | User Programs |
| Layer 4 | File System |
| Layer 3 | Process Management |
| Layer 2 | Memory Management |
| Layer 1 | Hardware Interface |
| Layer 0 | Hardware |
| Advantages | Disadvantages |
|---|---|
| Easy debugging | Slower due to layer overhead |
| Easy maintenance | Strict layer rules can be limiting |
| Better organization |
6. Modular Architecture
Combines advantages of both Monolithic and Microkernel. Modules can be loaded and unloaded dynamically without rebooting.
| Examples |
|---|
| Modern Linux kernels |
| Modern Windows kernels |
7. Virtual Machine Architecture
One physical machine behaves like multiple independent computers.
Example: One computer running Windows, Linux, and Ubuntu simultaneously.
| Structure |
|---|
| Guest OS | Guest OS | Guest OS |
| ↓ Hypervisor |
| ↓ Hardware |
Hypervisor
Software that manages virtual machines.
| Type | Runs On | Examples |
|---|---|---|
| Type 1 (Bare Metal) | Directly on hardware | VMware ESXi, Microsoft Hyper-V |
| Type 2 (Hosted) | On top of an existing OS | Oracle VM VirtualBox, VMware Workstation |
8. System Calls
System calls are requests made by user programs to the OS kernel for services.
Why Needed? Applications cannot directly access hardware. They must ask the kernel for services via system calls.
| Flow |
|---|
| Application ↓ System Call ↓ Kernel ↓ Hardware |
| Category | Examples |
|---|---|
| File Operations | Open file, Read file, Write file, Delete file |
| Process Operations | Create process, Terminate process |
| Device Operations | Read keyboard, Write printer |
📌 Exam Definition: System call is the interface between user programs and operating system services.
9. Interrupts
An interrupt is a signal that temporarily stops CPU execution and requests immediate attention.
Example: While typing, the keyboard sends an interrupt. The CPU pauses its current task, handles the keyboard event, then resumes.
| Type | Generated By | Examples |
|---|---|---|
| Hardware Interrupt | Physical devices | Keyboard, Mouse, Printer |
| Software Interrupt | Programs | System calls |
Interrupt Handling Steps
| Step | Action |
|---|---|
| 1 | Interrupt occurs |
| 2 | CPU saves current state |
| 3 | Interrupt Service Routine (ISR) executes |
| 4 | CPU restores previous state |
| 5 | Program continues |
10. Trap
A trap is a software-generated interrupt, usually generated intentionally by a program or due to an error.
| Examples of Traps | Cause |
|---|---|
| Division by Zero (10 ÷ 0) | Arithmetic error generates trap |
| System Calls | Also generate traps internally |
Interrupt vs Trap
| Feature | Interrupt | Trap |
|---|---|---|
| Source | External event | Internal event |
| Generated By | Hardware | Software |
| Example | Keyboard press | Divide by zero |
11. Context Switching
One of the most important OS concepts.
Definition: Saving the state of one process and loading the state of another process so the CPU can switch between them.
Example: You are watching YouTube and typing notes. The CPU rapidly switches between both tasks.
| What is Saved? | Where? |
|---|---|
| Program Counter | PCB (Process Control Block) |
| Registers | |
| Process State |
| Context Switch Process |
|---|
| Process A Running ↓ Save State of A ↓ Load State of B ↓ Process B Running |
| Why Needed? |
|---|
| Multitasking |
| Time-sharing |
| Scheduling |
⚠️ Important: Context switching creates overhead because the CPU performs no useful work during the switch itself.
12. Boot Process
Booting is the process of starting a computer and loading the OS into memory.
| Step | Action | Detail |
|---|---|---|
| 1 | Power On | Computer receives power |
| 2 | BIOS / UEFI Executes | Runs POST (Power-On Self-Test) — checks RAM, Keyboard, CPU, Storage |
| 3 | Boot Loader Loads | Loads OS kernel — e.g. GRUB (Linux), Windows Boot Manager |
| 4 | Kernel Loads | Kernel enters memory |
| 5 | System Initialization | Drivers loaded, services started |
| 6 | Login Screen | System ready for user |
Cold Boot vs Warm Boot
| Feature | Cold Boot | Warm Boot |
|---|---|---|
| Trigger | Power Off → On | Restart |
| Initialization | Full initialization | Faster |
| When Used | First startup | Reboot |
Design Goals of an OS
| Goal | Meaning |
|---|---|
| 1. Reliability | System should not crash |
| 2. Efficiency | Maximum hardware utilization |
| 3. Security | Protect resources from unauthorized access |
| 4. Scalability | Handle increasing workload |
| 5. Maintainability | Easy updates and bug fixes |
Quick Revision Table
| Concept | Definition |
|---|---|
| Kernel | Core part of OS |
| System Call | Interface between program and OS |
| Interrupt | Signal requesting CPU attention |
| Trap | Software-generated interrupt |
| Context Switch | Switching CPU between processes |
| Booting | Starting a computer and loading OS |
| Hypervisor | Software managing virtual machines |
| PCB | Process Control Block — stores process state |
Memory Tricks
| Mnemonic | Full Form |
|---|---|
| OS Architectures — MMLV |
M → Monolithic M → Microkernel L → Layered V → Virtual Machine |
| Boot Sequence — PBKSL |
P → Power On B → BIOS / UEFI K → Kernel Load S → System Initialization L → Login |
Practice MCQs
-
1. Which architecture keeps only essential services in the kernel?
A. Monolithic B. Layered C. Microkernel D. Modular
✅ Answer: C — Microkernel -
2. Which acts as an interface between applications and kernel?
A. Driver B. System Call C. Scheduler D. PCB
✅ Answer: B — System Call -
3. Which structure stores process information during context switching?
A. RAM B. File Table C. PCB D. Cache
✅ Answer: C — PCB (Process Control Block) -
4. Which occurs first during booting?
A. Kernel Loading B. Login Screen C. POST D. Driver Loading
✅ Answer: C — POST (Power-On Self-Test) -
5. Divide-by-zero error generates:
A. Hardware Interrupt B. DMA C. Trap D. Scheduler
✅ Answer: C — Trap