The CPU Scheduler module provides interactive visualization of process scheduling algorithms, helping understand how operating systems manage CPU time allocation.
CPU scheduling is a fundamental operating system concept that determines which process runs on the CPU at any given time. This module visualizes four major scheduling algorithms with real-time Gantt charts and performance metrics.
Type: Non-preemptive
Concept: Processes are executed in the order they arrive in the ready queue.
How it Works:
- Processes enter the ready queue in arrival order
- CPU allocated to the first process in queue
- Process runs to completion before next starts
- No preemption - once started, runs until finished
| Advantages | Disadvantages |
|---|---|
| Simple to implement | Poor average waiting time |
| Fair (arrival order) | Convoy effect |
| No starvation | Not suitable for time-sharing |
Best For: Batch systems where throughput > response time
Type: Non-preemptive (SJF) or Preemptive (SRTF)
Concept: Process with shortest burst time executes first.
Non-Preemptive (SJF):
- Sort processes by burst time
- Execute shortest job completely
- No interruption once started
Preemptive (SRTF):
- Check if new arrival has shorter remaining time
- Preempt current process if shorter job arrives
- Always runs minimum remaining time process
| Advantages | Disadvantages |
|---|---|
| Optimal average waiting time | Starvation for long processes |
| Good response for short jobs | Requires burst time prediction |
| Adapts to workload (SRTF) | High context switching (SRTF) |
Best For: Systems with known job durations
Type: Non-preemptive or Preemptive
Concept: Each process has a priority; highest priority (lowest number) runs first.
Non-Preemptive:
- Highest priority process runs to completion
- If priorities equal, uses FCFS tiebreaker
Preemptive:
- Higher priority arrival preempts current process
- CPU always runs highest priority ready process
| Advantages | Disadvantages |
|---|---|
| Important tasks get preference | Starvation of low priority |
| Flexible priority assignment | Priority inversion problem |
| Good for real-time systems | Difficult to set optimal priorities |
Best For: Systems with clear task importance hierarchy
Type: Preemptive
Concept: Each process gets a fixed time quantum; cycles through all processes.
How it Works:
- Each process gets a time quantum (configurable)
- Process runs for quantum or until completion
- If not finished, moves to end of ready queue
- Next process gets CPU
Time Quantum Guidelines:
- Too Small: High context switching overhead
- Too Large: Behaves like FCFS
- Optimal: 80% of processes should finish within one quantum
| Advantages | Disadvantages |
|---|---|
| Fair CPU sharing | Higher avg waiting than SJF |
| Good response time | Context switching overhead |
| No starvation | Performance depends on quantum |
Best For: Time-sharing and interactive systems
Real-time animated Gantt chart showing:
- Process execution timeline
- Process colors and durations
- Time markers
- Average Waiting Time: Mean time processes wait in ready queue
- Average Turnaround Time: Mean time from arrival to completion
- Average Response Time: Mean time from arrival to first execution
- CPU Utilization: Percentage of time CPU is busy
- Throughput: Processes completed per time unit
- Context Switches: Number of process switches
Compare all algorithms side-by-side with the same process set:
- FCFS
- SJF (Non-preemptive)
- SRTF (Preemptive SJF)
- Priority (Non-preemptive)
- Priority (Preemptive)
- Round Robin
Includes algorithm recommendation based on metrics.
- Demo Scenarios: Pre-built example configurations
- Import/Export: Save and load process configurations (JSON)
- Keyboard Shortcuts: R (run), C (clear), H (help)
- Step-by-Step Explanations: Educational view of scheduler decisions
- Sortable Process Table: Sort by any metric
POST /api/scheduler/run
Request Body:
{
"algorithm": "fcfs|sjf|priority|round_robin",
"processes": [
{"pid": 1, "arrival_time": 0, "burst_time": 5, "priority": 1}
],
"time_quantum": 4,
"preemptive": false
}Response:
{
"gantt_chart": [...],
"completed_processes": [...],
"metrics": {...},
"explanations": [...]
}POST /api/scheduler/compare
GET /api/scheduler/algorithms
pages/CPUScheduler.jsx- Main componentpages/CPUScheduler.css- Stylescomponents/ProcessTimeline.jsx- Gantt chartcomponents/MetricsPanel.jsx- Performance metricscomponents/ProcessInput.jsx- Process formcomponents/ComparisonPanel.jsx- Algorithm comparisoncomponents/ExplanationPanel.jsx- Step explanations
schedulers/base_scheduler.py- Abstract base classschedulers/fcfs.py- FCFS implementationschedulers/sjf.py- SJF/SRTF implementationschedulers/priority.py- Priority schedulingschedulers/round_robin.py- Round Robin implementationroutes/scheduler_routes.py- API endpoints
- Understand how different algorithms prioritize processes
- Compare algorithm trade-offs (waiting time vs. response time)
- Visualize process state transitions
- Analyze impact of preemption and time quantum
- Compare FCFS vs SJF with varying arrival times
- Observe convoy effect with one long and multiple short processes
- Test Round Robin with different quantum values
- Explore priority inversion scenarios