🧠 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

TypeDescriptionExample
Cooperative MultitaskingEach program voluntarily gives up CPU timeEarly MacOS, Windows 3.x
Preemptive MultitaskingOS forcibly switches between tasks using a timerLinux, Windows NT+, macOS

🛠️ How Multitasking Works (Preemptive Style)

  1. OS keeps a ready queue of processes/tasks.

  2. A timer interrupt triggers every few milliseconds.

  3. OS saves context (registers, PC, etc.) of current task.

  4. Restores context of next task from queue.

  5. 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

FeatureMultitaskingMultiprogrammingMultiprocessing
🎯 FocusUser experience — smooth execution of multiple appsResource utilizationParallelism
🔄 ExecutionFast switching (illusion of parallelism)Switch on I/O waitTrue simultaneous execution
🧠 System TypeSupported in modern OSLegacy conceptNeeds multiple CPUs
🛠️ ExampleBrowsing + Music + TerminalRun 3 jobs, switch on I/OOne 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

FeaturePurpose
⏱️ SchedulerDecides which task runs next
🔁 Context SwitchingSave/restore state between tasks
🔒 Memory ProtectionPrevent one task from corrupting another
🔂 I/O HandlingAsync 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.