CPU Scheduling is the method by which the operating system decides which process in the ready state will be allocated CPU time.
The CPU Scheduler uses a ready queue containing Process Control Blocks (PCBs) of processes that are ready to execute.
The ready queue does not necessarily follow a First-In-First-Out (FIFO) order.
The CPU-I/O Burst Cycle indicates that process execution consists of alternating cycles of CPU execution and I/O waiting.
Maximum CPU utilization can be achieved through multiprogramming by overlapping CPU bursts with I/O bursts.
The CPU scheduling decisions may occur under the following conditions:
Process switches from running to waiting state (e.g., I/O request).
Process switches from running to ready state (e.g., due to an interrupt).
Process switches from waiting to ready state (e.g., after I/O completion).
Process terminates.
Nonpreemptive scheduling occurs in conditions 1 and 4. All other situations involve preemptive scheduling.
The CPU Scheduler can take CPU away from a running process to allocate it to another process.
Preemptions may happen whenever interrupts occur, requiring the existing process to be temporarily suspended.
Care must be taken when accessing shared data to avoid simultaneous access issues.
Once a process is allocated the CPU, it retains it until it voluntarily releases it or terminates.
This type of scheduling is simpler and does not require additional hardware like a timer.
However, it has less flexibility in fulfilling timing constraints and may hinder responsiveness in some scenarios.
The dispatcher differentiates between CPU processes by managing context switching, switching to user mode, and executing processes as necessary.
Dispatch latency refers to the time taken by the dispatcher to switch from one process to another.
CPU Utilization: Aim to keep the CPU busy.
Throughput: The number of processes completed per time unit.
Turnaround Time: Total time from submission to completion (includes I/O wait).
Waiting Time: Total time spent by a process in the ready queue.
Response Time: Time from request submission to the first response, pertinent in interactive systems.
Example: Processes P1, P2, P3 with respective burst times.
Waiting time for P1 = 0, P2 = 24, P3 = 27
Average waiting time = (0 + 24 + 27)/3 = 17
Cons: Convoy effect can lead to poor responsiveness.
Prioritizes processes with the shortest next CPU burst.
Two Variants: Nonpreemptive and preemptive (Shortest-Remaining-Time-First, SRTF).
Considered optimal for minimizing average waiting time.
Each process receives a small time quantum (e.g., 10-100 ms).
If a process does not finish in its quantum, it is preempted and added back to the ready queue.
Average waiting time calculation is based on the total waiting time accumulated across processes.
The ready queue is partitioned into separate queues (e.g., foreground, background), each with its scheduling algorithm.
Fixed priority scheduling works with starvation risk for lower-priority processes.
Soft Real-Time: Critical tasks have highest priority but no guarantee of scheduling.
Hard Real-Time: Tasks must be serviced by specific deadlines.
Performance of scheduling algorithms can be analyzed using deterministic modeling for predetermined workloads.
Algorithms may be evaluated based on average waiting time calculations.
CPU Scheduling is essential to efficient process management, impacting overall system performance. Various strategies have their implications on responsiveness, utilization, and service quality, necessitating a fit-for-purpose approach tailored to system requirements.