A comprehensive terminal-based visualization tool for understanding and comparing CPU scheduling algorithms. This project simulates popular CPU scheduling algorithms with real-time progress visualization, metrics calculation, and comparative analysis features.
- Features
- Project Structure
- Scheduling Algorithms
- Installation
- Usage
- Input Methods
- Performance Metrics
- Implementation Details
- Contributing
- License
- Interactive Visualization: Terminal-based real-time visualization of process execution
- Multiple Scheduling Algorithms:
- First Come First Served (FCFS)
- Shortest Job First (SJF)
- Priority Scheduling
- Round Robin (RR) with customizable time quantum
- Priority Round Robin (Priority + RR hybrid)
- Detailed Metrics: Calculation and display of important performance metrics
- Comparative Analysis: Ability to run and compare all algorithms on the same process set
- Flexible Input Methods:
- Read process data from files
- Generate random processes with configurable parameters
- Manually enter process details
- Colorful Interface: ANSI color-coded visualization for easier understanding
OS-CPU-Scheduler/
├── include/ # Header files
│ ├── core/ # Core scheduler implementation
│ │ ├── FCFS.h # First Come First Served
│ │ ├── Priority.h # Priority Scheduling
│ │ ├── PriorityRR.h # Priority Round Robin
│ │ ├── Process.h # Process representation
│ │ ├── RR.h # Round Robin
│ │ ├── Scheduler.h # Base scheduler
│ │ └── SJF.h # Shortest Job First
│ └── utils/ # Utility classes
│ ├── Comparator.h # Algorithm comparison
│ ├── Drawer.h # Terminal visualization
│ ├── InputHandler.h # Process input handling
│ └── Selector.h # User interface elements
├── src/ # Source files
│ ├── core/ # Algorithm implementations
│ │ ├── FCFS.cpp
│ │ ├── Priority.cpp
│ │ ├── PriorityRR.cpp
│ │ ├── Process.cpp
│ │ ├── RR.cpp
│ │ ├── Scheduler.cpp
│ │ └── SJF.cpp
│ ├── utils/ # Utility implementations
│ │ ├── Comparator.cpp
│ │ ├── Drawer.cpp
│ │ ├── InputHandler.cpp
│ │ └── Selector.cpp
│ └── main.cpp # Entry point
├── test/ # Test files with sample process data
│ ├── 1.txt
│ ├── 2.txt
│ └── 3.txt
├── Makefile # Build configuration
└── README.md # This file
- Non-preemptive scheduling algorithm
- Processes are executed in the order they arrive
- Simple but can lead to the convoy effect
- Non-preemptive scheduling algorithm
- Selects the process with the shortest burst time
- Optimal for minimizing average waiting time
- Requires knowledge of burst time in advance
- Non-preemptive scheduling algorithm
- Processes are executed based on priority (lower value = higher priority)
- May lead to starvation of low-priority processes
- Preemptive scheduling algorithm
- Each process gets a fixed time quantum
- Fair allocation of CPU time but higher context-switching overhead
- Performance depends on time quantum selection
- Hybrid preemptive scheduling algorithm
- Combines priority scheduling with round robin
- Processes with higher priority are serviced first
- Round robin is applied within the same priority level
- C++17 compatible compiler (GCC 7+ or Clang 5+)
- Linux/UNIX terminal (for ANSI color support)
- GNU Make
- Clone the repository:
git clone https://github.com/your-username/OS-CPU-Scheduler.git
cd OS-CPU-Scheduler- Compile the project:
makeThis will create the executable in the bin directory.
./bin/app-
Select an operation mode:
- Single Algorithm Simulation
- Comparative Analysis (All Algorithms)
-
For Single Algorithm Simulation:
- Choose one of the scheduling algorithms
- If selecting Round Robin or Priority Round Robin, specify a time quantum
- Choose an input method for processes
- Watch the simulation visualize the algorithm
-
For Comparative Analysis:
- Configure process generation parameters
- Specify the time quantum for RR-based algorithms
- View and compare the performance metrics of all algorithms
Provide a text file where each line represents a process with space-separated values:
<Process ID> <Arrival Time> <Burst Time> <Priority>
Example (test/1.txt):
0 0 8 2
1 1 4 1
2 2 9 3
3 3 5 2
Configure parameters for random process generation:
- Number of processes
- Maximum arrival time
- Minimum/maximum burst time
- Maximum priority value
Enter process details one by one through the terminal interface.
The simulator calculates and displays these metrics:
- Average Waiting Time: The average time processes spend waiting in the ready queue
- Average Turnaround Time: The average time from process arrival to completion
- CPU Utilization: Percentage of time the CPU is busy executing processes
Represents a process with attributes like arrival time, burst time, priority, and methods to track its execution state.
Scheduler: Abstract base class defining the common interface- Algorithm-specific implementations (FCFS, SJF, etc.) that inherit from Scheduler
Uses ANSI escape codes to create a dynamic visualization with:
- Color-coded progress bars for process execution
- Real-time table of completed processes
- Final metrics display
- Initialize selected scheduler with processes
- Step through simulation, updating process states
- Calculate and display metrics when simulation completes
the doc folder contain walkthroughs of major folders in the project and explanations of the code within it.
Created by [Safae Hajjout & Yahya Mansoub ]
