Past exam question: 2075 (Past Questions), QE
Open in the Padhaiko appDifferentiate between I/O bound process and CPU bound process? What is process scheduling? Why do we need thread?
Solution
Differentiating I/O-Bound vs. CPU-Bound Processes: Processes alternate between computing on the CPU (CPU bursts) and waiting for I/O operations to complete (I/O bursts). Processes are categorized according to the dominant type of burst they spend their lifetime performing:
- I/O-Bound Process: Spends the majority of its time waiting for I/O operations (such as disk reads/writes, keyboard input, or network packets). It executes with many very short CPU bursts separated by frequent, relatively long I/O requests.
- CPU-Bound Process: Spends the vast majority of its execution time performing computational instructions in the CPU. It executes with a few very long, uninterrupted CPU bursts and performs infrequent, brief I/O operations.
| Feature | I/O-Bound Process | CPU-Bound Process |
|---|---|---|
| Burst Characteristic | Short CPU bursts, long and frequent I/O bursts. | Long CPU bursts, short and infrequent I/O bursts. |
| System Bottleneck | Secondary storage, network interface, or user response rate. | CPU arithmetic-logic speed and memory bus bandwidth. |
| Scheduler Priority | High priority (giving CPU briefly unblocks subsequent I/O). | Low/medium priority (run in background without starving I/O). |
| CPU Utilization Impact | Low per process; relies on multiprogramming to keep CPU busy. | High; tends to monopolize the CPU if un-preempted. |
| Examples | Text editors, web browsers, database queries, file copy tools. | Scientific simulations, 3D rendering, video encoding, cryptography. |
Process Scheduling Concept and Objectives: Process scheduling is the foundational operating system mechanism by which the CPU scheduler (short-term scheduler) selects an executable process from the ready queue and allocates the CPU to it.
- Primary Purpose: In a multiprogrammed system, multiple processes compete for limited physical processor cores. Process scheduling ensures the CPU is multiplexed efficiently, preventing starvation and maintaining high system throughput.
- Core Criteria:
- CPU Utilization: Keeping the CPU as busy as possible ( to ).
- Throughput: Maximizing the number of completed processes per unit time.
- Turnaround Time: Minimizing the elapsed time from process submission to completion.
- Waiting Time: Minimizing total time spent waiting in the ready queue.
- Response Time: Minimizing the duration from request submission to the first response (crucial for interactive systems).
- Scheduling Disciplines:
- Non-preemptive (Cooperative): Once the CPU is allocated to a process, it retains the CPU until it voluntarily terminates or blocks for I/O (e.g., FCFS, non-preemptive SJF).
- Preemptive: The scheduler can forcibly interrupt a running process when a higher-priority process arrives or when a timer quantum expires (e.g., Round Robin, SRTF, Preemptive Priority).
Why We Need Threads (Lightweight Processes): A thread is the smallest schedulable unit of CPU execution within a process. Multiple threads within the same process share its code section, data section, heap, and open OS resources (e.g., file descriptors), but each maintains its own private Program Counter (PC), register set, and execution stack.
Threads are essential for four primary engineering reasons:
- Enhanced Responsiveness: In interactive desktop and web applications, executing long-running operations (such as file downloads or database indexing) in a background worker thread ensures the user interface thread remains completely responsive to user clicks and inputs.
- Resource Sharing and Memory Efficiency: Creating multiple processes requires duplicating entire virtual address spaces and page tables. Threads share the parent process's memory space, drastically reducing memory consumption.
- Low Creation and Context-Switching Overhead: Creating a thread is roughly 10 to 30 times faster than spawning a new process via
fork(). Context-switching between threads of the same process is extremely lightweight because memory mapping tables do not change, avoiding expensive Translation Lookaside Buffer (TLB) flushes. - Multicore Parallelism and Scalability: On modern multi-core and multi-processor hardware, different threads of a single application can execute simultaneously on separate physical CPU cores, achieving true hardware parallelism and linear speedup for compute-intensive tasks.
An I/O-bound process is characterized by frequent, short CPU bursts dominated by I/O wait times (e.g., text editors), whereas a CPU-bound process performs long, sustained computational bursts with minimal I/O (e.g., scientific modeling). Process scheduling is the OS mechanism that allocates CPU cores among ready processes to optimize CPU utilization, throughput, latency, and fairness. Threads (lightweight processes) are needed to provide interactive responsiveness, enable efficient memory sharing, minimize creation and context-switch overhead, and exploit true multicore hardware parallelism.