Chapter 9: Multitasking and Multiprocessing

Syllabus 9.5 — Multitasking, Multiprogramming, Multithreading & Multiprocessing

1. Evolution of CPU Utilization

Early ComputersModern Computers
One user at a timeMany users simultaneously
One program at a timeMany programs running together
CPU idle most of the timeCPU utilization maximized
No multitaskingMultitasking + Multiprocessing

Modern operating systems maximize CPU utilization through multitasking and multiprocessing.


2. What is Multitasking?

Multitasking is the ability of an OS to execute multiple tasks apparently at the same time by rapidly switching the CPU among them.

📌 On a single-core processor, only one task actually executes at any instant. The illusion of simultaneous execution is created through context switching.

CharacteristicDetail
Multiple applicationsRun concurrently
CPU timeShared among tasks
MechanismProcess scheduling + context switching
User experienceAll tasks appear to run together
AdvantagesDisadvantages
Better CPU utilizationContext switching overhead
Increased productivityHigher memory requirements
Improved responsivenessPoor scheduling degrades performance

3. Types of Multitasking

A. Cooperative Multitasking

Each running process voluntarily releases the CPU. The OS cannot forcibly interrupt the process.

AspectDetail
CPU ReleaseProcess decides when to yield
AdvantageSimple implementation, low overhead
DisadvantageOne faulty program can block the entire system
Historical ExamplesWindows 3.x, Classic Mac OS

B. Preemptive Multitasking

The OS can interrupt a running process whenever necessary (e.g., when the time quantum expires).

AspectDetail
CPU ReleaseOS forces the switch
AdvantageBetter responsiveness; fair CPU allocation; faulty process isolated
DisadvantageMore context switching; slightly higher overhead
ExamplesModern Windows, Linux, macOS

Cooperative vs Preemptive

FeatureCooperativePreemptive
CPU controlReleased voluntarily by processTaken by OS
ComplexitySimplerMore complex
ResponsivenessLess responsiveMore responsive
Faulty processCan freeze entire systemIsolated; OS can evict it
UsageLegacy systemsAll modern OS

4. Time-Sharing System

A Time-Sharing System divides CPU time into small slices (time quanta) and shares them among users or processes to enable interactive computing.

AdvantageExample
Interactive computing for many usersUNIX servers, cloud terminals
Fair CPU allocationEach user gets a time slice
Multiple users simultaneouslyUniversity mainframe systems

5. What is Multiprocessing?

Multiprocessing means a computer uses two or more CPUs or processor cores to execute processes simultaneously. Unlike multitasking, tasks truly execute in parallel.

CharacteristicDetail
ProcessorsMultiple physical or logical CPUs
ExecutionTrue parallel execution
ThroughputHigher than single-CPU system
ReliabilityIf one CPU fails, others continue
AdvantagesDisadvantages
Faster execution & better performanceHigher hardware cost
Increased reliabilityMore complex OS required
Supports parallel computingInter-processor communication overhead

6. Types of Multiprocessing

A. Symmetric Multiprocessing (SMP)

All processors are equal — each can perform any task and all share the same memory.

AspectDetail
Processor rolesAll equal; any processor can run any process
MemoryShared among all processors
AdvantageLoad shared equally; high performance; better fault tolerance
ExamplesModern desktop computers, servers, smartphones

B. Asymmetric Multiprocessing (AMP)

One processor acts as the master; remaining processors work as slaves under its control.

AspectDetail
Master CPUControls scheduling and I/O
Slave CPUsExecute assigned tasks only
AdvantageSimpler control structure
DisadvantageLess flexible; master can become a bottleneck
ExamplesSome embedded systems, older mainframes

SMP vs AMP

FeatureSMPAMP
CPU rolesAll equalMaster-slave architecture
PerformanceBetter (load balanced)Simpler but less flexible
Fault toleranceHighLower (master failure = system failure)
Usage todayWidely used in modern systemsLess common

7. Multicore Processors

A multicore processor contains multiple processing cores within a single physical CPU chip.

ExampleDetail
Dual-Core2 cores in one chip
Quad-Core4 cores in one chip
Octa-Core8 cores in one chip
FeatureCPU (Physical Package)Core
DefinitionPhysical processor chipProcessing unit inside the CPU
ContainsOne or more coresALU, registers, cache
ExampleIntel Core i7Each of the 8 cores inside

Benefits: Lower power consumption per task, higher overall performance, better multitasking without needing separate physical CPUs.


8. Processor Affinity

Processor Affinity means keeping a process on the same CPU whenever possible to take advantage of warm cache data.

Without AffinityWith Affinity
Process may move to a different CPUProcess stays on same CPU
Cache data becomes cold (wasted)Cache still holds useful data
More cache missesFewer cache misses
Slightly lower performanceBetter performance

9. Load Balancing

Load balancing distributes processes evenly among all processors to prevent any single CPU from being overloaded while others sit idle.

ScenarioCPU 1CPU 2Result
Without load balancing10 processes1 processCPU 1 overloaded; CPU 2 idle
With load balancing5-6 processes5-6 processesEven utilization; better performance

10. Parallel Computing

Parallel computing uses multiple processors simultaneously to solve one large problem faster.

ExampleHow Parallel
Weather ForecastingEach processor calculates a different geographic region
Machine Learning TrainingDifferent batches of data processed simultaneously
Scientific SimulationsDifferent parts of the model computed at the same time
AI / Deep LearningGPU cores run thousands of operations in parallel

Key Comparisons

FeatureMultiprogrammingMultitasking
GoalMaximize CPU utilizationMaximize user interaction
CPU switch triggerProcess waits (I/O)Time slice expires
System typeMostly batch systemsInteractive systems
Concept eraOlderModern
FeatureMultitaskingMultiprocessing
HardwareOne CPU / core switching among tasksMultiple CPUs / cores
Execution typeConcurrency (interleaved)Parallelism (simultaneous)
MechanismContext switchingSimultaneous execution
FeatureMultiprocessingMultithreading
UnitMultiple CPUs / coresMultiple threads inside one process
BasisHardware-level parallelismSoftware execution units
CostHigher hardware costLower overhead

Concurrency vs Parallelism

FeatureConcurrencyParallelism
DefinitionMultiple tasks make progress during overlapping timeMultiple tasks execute at the exact same instant
CPU requirementSingle CPU is sufficient (context switching)Multiple cores required
ExecutionInterleaved (rapid switching)Truly simultaneous
ExampleOne CPU switching among Task A, B, CCore 1 → Task A, Core 2 → Task B
FeatureSingle-CoreMulti-Core
Execution unitsOneMultiple
Context switchingMore neededLess needed
ThroughputLowerHigher
CostLowerHigher performance

Memory Tricks

MnemonicFull Form
Multitasking Types — CP C → Cooperative   P → Preemptive
Multiprocessing Types — SA S → Symmetric (SMP)   A → Asymmetric (AMP)
CPU Sharing Goals — ULTP U → Utilization   L → Load Balancing   T → Throughput   P → Performance
Concurrency vs Parallelism Concurrency = one CPU, overlapping. Parallelism = multiple cores, simultaneous.

Frequently Asked Exam Questions

QuestionAnswer
What is multitasking?OS ability to execute multiple tasks by rapidly switching the CPU among them
What is multiprocessing?Use of multiple CPUs or cores to execute processes simultaneously
Cooperative vs preemptive multitasking?Cooperative: process voluntarily yields. Preemptive: OS interrupts the process.
What is SMP?Symmetric Multiprocessing — all processors equal, share memory, run any task
What is processor affinity?Keeping a process on the same CPU to improve cache performance
Concurrency vs parallelism?Concurrency: overlapping progress (one CPU). Parallelism: simultaneous execution (multiple cores).
Multitasking vs multiprocessing?Multitasking: one CPU switches (concurrency). Multiprocessing: multiple CPUs run in parallel.

Practice MCQs

  • 1. Which multitasking type allows the OS to interrupt a running process?
    A. Cooperative   B. Batch   C. Preemptive   D. Sequential
    ✅ Answer: C — Preemptive
  • 2. Which multiprocessing model treats all processors equally?
    A. Asymmetric Multiprocessing   B. Symmetric Multiprocessing   C. Batch Processing   D. Time Sharing
    ✅ Answer: B — Symmetric Multiprocessing (SMP)
  • 3. Time-sharing systems primarily aim to:
    A. Reduce RAM usage   B. Share CPU time among users or processes   C. Eliminate context switching   D. Remove deadlocks
    ✅ Answer: B — Share CPU time among users or processes
  • 4. Which concept keeps a process on the same CPU to improve cache efficiency?
    A. Paging   B. Processor Affinity   C. Spooling   D. Segmentation
    ✅ Answer: B — Processor Affinity
  • 5. True parallel execution requires:
    A. One CPU only   B. Multiple processors or cores   C. A larger hard disk   D. More RAM only
    ✅ Answer: B — Multiple processors or cores