CPU Scheduling Simulator
Simulate FCFS, SJF, SRTF, Priority, and Round Robin scheduling. Add processes, pick an algorithm, and instantly see the Gantt chart with waiting time, turnaround time, and response time.
| Process | Arrival (ms) | Burst (ms) | Priority | |
|---|---|---|---|---|
Algorithm
CPU Scheduling Algorithm Overview
CPU scheduling is the operating system mechanism that decides which process runs next when the CPU is available. The scheduler's goal is to maximize CPU utilization and throughput while minimizing waiting time, turnaround time, and response time. The right algorithm depends on the workload: batch systems prioritize throughput, interactive systems prioritize response time, and real-time systems prioritize deterministic deadlines.
| Algorithm | Preemptive | Starvation | Best for |
|---|---|---|---|
| FCFS | No | No | Simple batch systems |
| SJF | No | Yes | Minimizing avg. wait (non-preemptive) |
| SRTF | Yes | Yes | Theoretical minimum wait time |
| Priority | No | Yes | Real-time tasks with known importance |
| Round Robin | Yes | No | Interactive, time-sharing systems |
Key Metrics: Waiting, Turnaround, and Response Time
These three metrics quantify scheduling quality from different perspectives:
Waiting Time
finish − arrival − burstTotal time spent in the ready queue. Directly measures CPU starvation. Lower is better.
Turnaround Time
finish − arrivalTotal time from submission to completion. The most common batch performance metric.
Response Time
first_start − arrivalTime until first CPU allocation. Critical for interactive feel. Used in UI responsiveness budgets.
Reading the Gantt Chart
A Gantt chart is a horizontal bar chart where the x-axis represents time and each colored segment shows which process was executing during that interval. Gray segments indicate idle CPU time — periods when no process was in the ready queue. The numbers below each segment boundary are the time ticks at which context switches occurred. In preemptive algorithms (SRTF, Round Robin), the same process may appear multiple times in non-contiguous segments. Comparing Gantt charts across algorithms reveals the trade-offs: SRTF typically produces the fewest idle gaps and shortest overall completion time, while Round Robin produces the most evenly distributed segments.
Frequently Asked Questions
What is the difference between FCFS and SJF scheduling?
First Come, First Served (FCFS) executes processes strictly in arrival order with no preemption. It is the simplest algorithm to implement but suffers from the convoy effect — a long process blocks all shorter ones behind it, leading to high average waiting times. Shortest Job First (SJF) always picks the process with the smallest burst time from those currently available. SJF is optimal in terms of minimizing average waiting time for a given set of non-preemptive processes, but it requires advance knowledge of burst times, which is rarely available in practice. It can also cause starvation of long processes.
What is SRTF and how does it differ from SJF?
Shortest Remaining Time First (SRTF) is the preemptive version of SJF. Whenever a new process arrives, the scheduler checks if its burst time is less than the remaining time of the currently running process. If so, it preempts the current process and switches to the new one. SRTF achieves the minimum possible average waiting time among all preemptive algorithms but has high context-switching overhead. It is theoretically optimal but nearly impossible to implement in practice since future CPU burst times are unknown.
How does Round Robin scheduling work and what is the time quantum?
Round Robin (RR) assigns each ready process a fixed time slice called the time quantum (or time slice). After each quantum expires, the current process is preempted and moved to the back of the ready queue, giving the next process its turn. This ensures fairness and bounded response time, making RR the dominant algorithm in interactive and time-sharing operating systems. The quantum size is critical: too small causes excessive context-switching overhead; too large degrades RR toward FCFS behavior. Typical Linux CFS quantum is around 1–4 ms for interactive tasks.
What are waiting time, turnaround time, and response time?
Turnaround time is the total time from process submission to completion: turnaround = finish − arrival. Waiting time is the portion of turnaround time that the process spent waiting in the ready queue (not executing): waiting = turnaround − burst. Response time is the time from first arrival to first execution: response = first_start − arrival. For non-preemptive algorithms, response time equals waiting time. For preemptive algorithms like SRTF and RR, a process may start quickly (low response) but still accumulate waiting time across multiple preemptions.
When should I use Priority scheduling versus Round Robin?
Priority scheduling is appropriate when processes have inherently different importance levels — for example, real-time interrupt handlers, system daemons, and user processes. Lower priority numbers indicate higher priority in this simulator (matching Unix nice values). Pure priority scheduling risks starvation: low-priority processes may never run if high-priority ones keep arriving. Round Robin is better for interactive systems where fairness matters more than priority. Most real-world operating systems (including Linux, Windows, and macOS) use a multi-level feedback queue that combines both: high-priority processes run first, but their priority decays over time if they use too much CPU, preventing starvation.