🧠 What is Multitasking?
Multitasking is the Operating System’s ability to run multiple tasks (processes or threads) seemingly at the same time, giving users the impression that everything is running simultaneously.
The key word is “illusion of simultaneity” — even on a single CPU, the OS can switch fast enough between tasks that it feels like they’re running together.
🔁 Types of Multitasking
| Type | Description | Example |
|---|---|---|
| Cooperative Multitasking | Each program voluntarily gives up CPU time | Early MacOS, Windows 3.x |
| Preemptive Multitasking | OS forcibly switches between tasks using a timer | Linux, Windows NT+, macOS |
🛠️ How Multitasking Works (Preemptive Style)
-
OS keeps a ready queue of processes/tasks.
-
A timer interrupt triggers every few milliseconds.
-
OS saves context (registers, PC, etc.) of current task.
-
Restores context of next task from queue.
-
CPU starts executing the next task.
This switch is called a context switch, and it happens so fast (ms) that users don’t notice.
⚙️ Multitasking vs Multiprogramming vs Multiprocessing
| Feature | Multitasking | Multiprogramming | Multiprocessing |
|---|---|---|---|
| 🎯 Focus | User experience — smooth execution of multiple apps | Resource utilization | Parallelism |
| 🔄 Execution | Fast switching (illusion of parallelism) | Switch on I/O wait | True simultaneous execution |
| 🧠 System Type | Supported in modern OS | Legacy concept | Needs multiple CPUs |
| 🛠️ Example | Browsing + Music + Terminal | Run 3 jobs, switch on I/O | One core for Chrome, one for VS Code |
🧪 Real-World Example
You are:
-
Downloading a file
-
Writing code
-
Watching a video
Even with one CPU, your OS can interleave time slices between all these tasks — that’s multitasking.
🔐 Key OS Features Required for Multitasking
| Feature | Purpose |
|---|---|
| ⏱️ Scheduler | Decides which task runs next |
| 🔁 Context Switching | Save/restore state between tasks |
| 🔒 Memory Protection | Prevent one task from corrupting another |
| 🔂 I/O Handling | Async operations to keep CPU busy |
🧠 Interview-Ready Definition:
Multitasking is the OS’s ability to execute multiple tasks concurrently by rapidly switching the CPU between them. It enhances responsiveness and allows users to run several applications at once, even on a single CPU, through preemptive or cooperative task management.