Multitasking Operating Systems
Multitasking is a logical extension of multiprogramming. While multiprogramming was designed to keep the CPU busy during I/O waits, multitasking was designed to provide a smooth, interactive experience for the user by rapidly switching the CPU between different tasks.
What is Multitasking?
Multitasking (also known as Time-Sharing) allows multiple tasks or processes to share the CPU. Instead of waiting for a task to be 'blocked' by an I/O request, the OS actively switches between tasks at very high speeds.
Each task is given a tiny slice of CPU time, typically in milliseconds. Because the switching happens so fast, it creates the illusion that all programs are running simultaneously.
Working of a Multitasking OS
The core mechanism behind multitasking is the Time Slice or Quantum. The OS scheduler manages a queue of ready tasks and performs the following cycle:
- Allocation: The scheduler picks a task from the 'Ready' queue and assigns it to the CPU.
- Execution: The task runs for a predetermined duration (the quantum).
- Context Switching: Once the time slice expires, the OS saves the task's state (registers, program counter) and puts it at the back of the queue.
- Repeat: The next task in the queue is loaded and the process continues.
Examples of Multitasking Systems
Almost every modern general-purpose operating system is a multitasking system:
1. Windows (10, 11, etc.) 2. Linux (Ubuntu, Fedora, CentOS) 3. macOS 4. Android and iOS
Advantages & Disadvantages
| Feature | Details |
|---|---|
| Advantage: Short Response Time | Users don't have to wait for a long job to finish before getting a response from their application. |
| Advantage: Better User Experience | Allows running a browser, a music player, and a code editor at the same time without lag. |
| Disadvantage: High Overhead | Frequent context switching consumes CPU cycles that could have been used for actual work. |
| Disadvantage: Resource Contention | Multiple programs compete for limited RAM and disk space, which can slow down the system if not managed well. |
Multitasking vs Multiprogramming
The primary difference lies in *why* and *how* the OS switches between tasks.
| Attribute | Multiprogramming | Multitasking |
|---|---|---|
| Objective | Maximize CPU utilization (keep CPU busy). | Minimize response time (provide interactive experience). |
| Switch Trigger | Triggered by an I/O wait or task completion. | Triggered by a fixed time slice (timer interrupt). |
| Interaction | Low. Users submit jobs and wait for output. | High. Users interact with programs in real-time. |
| Core Concept | Filling I/O gaps. | Sharing CPU time (Time-Sharing). |
