TutorialsOperating Systems
Core CS

Process Scheduling

Process Scheduling is the operating system mechanism that determines which runnable process receives the CPU's execution time and resources when multiple processes compete for processing power. By rapidly switching the CPU among different tasks, the scheduler ensures high CPU utilization, prevents process starvation, and maintains responsive system performance in a multiprogramming or multitasking environment.

<p></p><h2><!--StartFragment--><p><b>Definition</b></p><p>At its core, process scheduling is the fundamental subsystem of the OS kernel responsible for removing an active process from the CPU and selecting another process from the ready queue based on a predetermined strategy or algorithm. It bridges the gap between limited hardware execution cores and a potentially massive volume of concurrent user and system threads, optimizing resource allocation according to performance criteria like latency, fairness, and throughput.</p><p><b style="font-family:Inter, ui-sans-serif, system-ui, -apple-system,"><br></b></p><p><b style="font-family:Inter, ui-sans-serif, system-ui, -apple-system,">Types of Schedulers</b></p><ul><li><p><b>Long-Term Scheduler (Job Scheduler):</b> Determines which programs are admitted into the primary memory from the secondary storage pool, directly controlling the <b>degree of multiprogramming</b>.</p></li><li><p><b>Short-Term Scheduler (CPU Scheduler):</b> Executes frequently to select a process from the <b>Ready Queue</b> and allocate the CPU core via the dispatcher.</p></li><li><p><b>Medium-Term Scheduler:</b> Handles process swapping between main memory and secondary storage (virtual memory) to manage memory congestion and reduce the multiprogramming level when needed.</p></li></ul><p><b>Scheduling Modes</b></p><ul><li><p><b>Non-Preemptive:</b> Once a process takes control of the CPU, it holds it until it either terminates or voluntarily yields control (e.g., waiting for an I/O operation).</p></li><li><p><b>Preemptive:</b> The operating system can interrupt and suspend a currently running process to assign the CPU to a higher-priority or newly arrived task, typically triggered by hardware timer interrupts or priority shifts.</p></li></ul><p><b>Core Performance Criteria</b></p><ul><li><p><b>CPU Utilization:</b> Keeping the CPU working as close to 100% of the time as possible.</p></li><li><p><b>Throughput:</b> Maximizing the total count of completed processes per unit of time.</p></li><li><p><b>Turnaround Time:</b> Minimizing the total interval from process submission to complete termination.</p></li><li><p><b>Waiting Time:</b> Minimizing the total duration a process spends waiting inside the ready queue.</p></li><li><p><b>Response Time:</b> Minimizing the elapsed time between submitting a request and the first observable response.</p></li></ul><p><b>Common Scheduling Algorithms</b></p><ul><li><p><b>First-Come, First-Served (FCFS):</b> Non-preemptive queue-based execution; prone to the convoy effect where short processes get stuck behind lengthy jobs.</p></li><li><p><b>Shortest Job First (SJF) / Shortest Remaining Time First (SRTF):</b> Prioritizes processes with the smallest CPU burst time, achieving optimal average waiting times. SJF is of non preemptive type whereas SRTF is of preemptive type.</p></li><li><p><b>Round Robin (RR):</b> Preemptive scheduling where each process gets a fixed slice of time (<b>time quantum</b>), ideal for interactive time-sharing systems.</p></li><li><p><b>Priority Scheduling:</b> Assigns execution rank based on internal or external factors; requires aging techniques to prevent the starvation of low-priority tasks.</p></li><li><p><b>Multilevel Feedback Queue (MLFQ):</b> Separates processes across multiple queues based on their CPU-burst behaviour, dynamically adjusting priorities over time.</p><!--EndFragment--></li></ul><!--EndFragment--></h2><p></p>