A comprehensive C++ implementation of fundamental CPU scheduling algorithms with performance analysis and Gantt chart visualization. This educational tool demonstrates how different scheduling strategies affect system performance metrics.
-
Multiple Scheduling Algorithms:
- First Come First Serve (FCFS/FIFO)
- Shortest Job First (SJF)
- Shortest Time to Completion First (STCF/SRTF)
- Round Robin (RR) with configurable time quantum
-
Visual Analysis:
- Interactive Gantt chart generation
- Process execution timeline visualization
- Color-coded process representation
-
Performance Metrics:
- Average turnaround time
- Average waiting time
- Average response time
- CPU utilization percentage
- Context switch analysis
-
Flexible Input System:
- File-based process definition
- Multiple test scenarios included
- Custom process creation support
- Compiler: C++11 compatible compiler (g++, clang++, MSVC)
- Build System: Make utility
- Operating System: Cross-platform (Linux, macOS, Windows)
git clone https://github.com/T41h4X/os-scheduling-algorithms.git
cd os-scheduling-algorithmsmake allmake testmake clean./bin/scheduler <algorithm> <input_file> [options]fcfsorfifo- First Come First Servesjf- Shortest Job Firststcforsrtf- Shortest Time to Completion Firstrr- Round Robin
--no-gantt- Disable Gantt chart display--detailed- Show detailed performance metrics--help- Display help information
# Run FCFS algorithm with simple test data
./bin/scheduler fcfs test_data/simple.txt
# Run Round Robin with detailed metrics
./bin/scheduler rr test_data/interactive.txt --detailed
# Run SJF without Gantt chart
./bin/scheduler sjf test_data/mixed.txt --no-gantt
# Display help information
./bin/scheduler --helpscheduling/
├── include/ # Header files
│ ├── scheduler.h # Main scheduler interface
│ ├── process.h # Process class definition
│ ├── gantt_chart.h # Gantt chart utilities
│ ├── performance.h # Performance metrics
│ └── file_parser.h # Input file parsing
├── src/ # Core implementation
│ ├── scheduler.cpp # Base scheduler logic
│ ├── process.cpp # Process management
│ ├── gantt_chart.cpp# Visualization code
│ └── file_parser.cpp# File I/O operations
├── schedulers/ # Algorithm implementations
│ ├── fcfs.cpp # First Come First Serve
│ ├── sjf.cpp # Shortest Job First
│ ├── stcf.cpp # Shortest Time to Completion
│ └── round_robin.cpp# Round Robin
├── metrics/ # Performance analysis
│ └── performance.cpp# Metrics calculation
├── test_data/ # Sample input files
│ ├── simple.txt # Basic test case
│ ├── interactive.txt# Interactive processes
│ ├── mixed.txt # Mixed workload
│ ├── priority.txt # Priority-based processes
│ └── simultaneous.txt# Simultaneous arrivals
├── tests/ # Unit tests
├── bin/ # Compiled executables
├── obj/ # Object files
├── Makefile # Build configuration
└── README.md # This file
Process files should follow this format:
# Process_ID Arrival_Time Burst_Time [Priority]
P1 0 5
P2 1 3
P3 2 8
P4 3 6
- Process_ID: Unique identifier for the process
- Arrival_Time: When the process arrives in the system
- Burst_Time: CPU time required by the process
- Priority: Optional priority value (higher number = higher priority)
Loading processes from: test_data/simple.txt
Loaded 4 processes
=== FCFS Scheduling Results ===
Process Execution Order: P1 → P2 → P3 → P4
Gantt Chart:
| P1 | P2 | P3 | P4 |
0 5 8 16 22
Performance Metrics:
- Average Turnaround Time: 11.25
- Average Waiting Time: 5.75
- Average Response Time: 5.75
- CPU Utilization: 100.00%
- Total Context Switches: 3
The project includes comprehensive test cases:
- simple.txt: Basic 4-process scenario
- interactive.txt: Short, frequent processes
- mixed.txt: Combination of CPU and I/O bound processes
- simultaneous.txt: All processes arrive at time 0
- priority.txt: Priority-based scheduling scenarios
# Test each algorithm with different datasets
./bin/scheduler fcfs test_data/simple.txt
./bin/scheduler sjf test_data/simple.txt
./bin/scheduler rr test_data/interactive.txt
./bin/scheduler stcf test_data/mixed.txtThis simulator is designed for:
- Operating Systems Courses: Understanding CPU scheduling concepts
- Algorithm Analysis: Comparing scheduling algorithm performance
- System Performance: Learning about metrics and optimization
- Research Projects: Baseline for advanced scheduling research
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-algorithm) - Commit your changes (
git commit -am 'Add new scheduling algorithm') - Push to the branch (
git push origin feature/new-algorithm) - Create a Pull Request
- Strategy: Execute processes in arrival order
- Advantages: Simple, fair, no starvation
- Disadvantages: Poor average waiting time, convoy effect
- Strategy: Execute shortest remaining job first
- Advantages: Optimal average waiting time
- Disadvantages: Starvation of long processes, requires burst time knowledge
- Strategy: Time-sliced execution with configurable quantum
- Advantages: Fair, good response time, no starvation
- Disadvantages: Higher context switch overhead
- Strategy: Preemptive SJF with remaining time consideration
- Advantages: Better response time than SJF
- Disadvantages: Complex implementation, starvation possible
This project is licensed under the MIT License - see the LICENSE file for details.
T41h4X
- GitHub: @T41h4X
- Repository: os-scheduling-algorithms
- Operating Systems concepts from modern textbooks
- CPU scheduling algorithm research papers
- Educational resources from computer science curriculum
⭐ Star this repository if you found it helpful!