CPU Scheduling and Process Management
CPU Scheduling and Process Management
1. Basic Concepts:
CPU scheduling is a fundamental aspect of operating system design, ensuring optimal
CPU utilization by executing multiple programs efficiently through multiprogramming.
CPU-I/O Burst
CPU-I/O Burst: The time a process spends on CPU execution and I/O operations.
CPU-I/O Burst Cycle: Process execution involves alternating between CPU execution
(CPU burst) and waiting for I/O operations (I/O burst).
Since CPU is one of the core computing resources, efficient CPU scheduling is crucial
for operating system performance.
CPU Bursts
The duration of CPU bursts follows an exponential or hyper-exponential distribution.
Characteristics of CPU bursts:
o Most CPU bursts are short.
o Few CPU bursts are long.
Process behavior based on CPU bursts:
o I/O-bound processes: Have many short CPU bursts.
o CPU-bound processes: Have fewer but longer CPU bursts.
o
CPU Scheduler
The CPU scheduler (or CPU manager) selects processes from the ready queue and
allocates CPU cores.
The ready queue can be ordered using different scheduling strategies.
CPU scheduling occurs in four situations:
1. When a process switches from running to waiting state (e.g., waiting for I/O).
2. When a process switches from running to ready state (e.g., interrupted).
3. When a process switches from waiting to ready state (e.g., I/O completed).
4. When a process terminates.
In cases 1 and 4, scheduling is mandatory (no choice).
In cases 2 and 3, the scheduler has a choice of which process to execute next.
Preemptive vs. Nonpreemptive Scheduling
Nonpreemptive Scheduling: Once a process is assigned to the CPU, it keeps it until it
either terminates or moves to the waiting state.
Preemptive Scheduling: The CPU can be taken away from a running process when a
higher-priority process arrives.
Modern operating systems (Windows, Linux, MacOS, UNIX) use preemptive
scheduling.
Dispatcher
The dispatcher is a module responsible for switching CPU control between processes
selected by the scheduler.
The dispatcher performs:
o Context switching
o Mode switching (from kernel mode to user mode)
o Jumping to the correct program location to resume execution
Dispatch latency: The time taken to stop one process and start another.
Scheduling Criteria
CPU Utilization: Keep the CPU busy as much as possible.
Throughput: Number of processes completed per time unit.
Turnaround Time: Time taken from submission to completion of a process.
Waiting Time: Time spent in the ready queue waiting for execution.
Response Time: Time from request submission to the first response.
Scheduling Algorithm Optimization Criteria
Scheduling algorithms are designed to:
o Maximize CPU utilization and throughput.
o Minimize turnaround time, waiting time, and response time.
The choice of a scheduling algorithm depends on system requirements and workload
characteristics.
5. Priority Scheduling
Each process is assigned a priority value.
The CPU executes the highest priority process first.
Types:
o Preemptive: Higher priority process interrupts a running process.
o Nonpreemptive: Once a process starts, it runs until completion.
Example
Queue Scheduling Algorithm
System Processes Highest Priority
Interactive Processes Round Robin
Background Processes FCFS