A Java-based simulation tool that implements and compares multiple CPU scheduling algorithms. This project demonstrates various process scheduling strategies and their performance metrics.
This simulator implements the following CPU scheduling algorithms:
- FCFS (First Come First Served) - Processes are executed in the order they arrive
- SJF (Shortest Job First) - Non-Preemptive - The shortest job is selected first, but once started, it runs to completion
- SJF Preemptive - The shortest remaining time job can preempt the currently running process
- Priority Scheduling - Processes are scheduled based on their priority levels
- Round Robin - Processes are executed in time slices (quantum), providing fair CPU time distribution
CPU-scheduling/
├── src/
│ └── main/
│ ├── java/
│ │ └── com/
│ │ └── cpuScheculing/
│ │ ├── App.java # Main application entry point
│ │ ├── model/
│ │ │ └── Process.java # Process data model
│ │ ├── scheduler/
│ │ │ ├── FCFS.java # First Come First Served scheduler
│ │ │ ├── SJF.java # Shortest Job First (Non-Preemptive)
│ │ │ ├── SJFPreemptive.java # Shortest Job First (Preemptive)
│ │ │ ├── PriorityScheduling.java # Priority-based scheduler
│ │ │ └── RoundRobin.java # Round Robin scheduler
│ │ └── util/
│ │ ├── FileReaderUtil.java # Utility for reading processes from file
│ │ └── IndividualCPUScheduler.java
│ └── resources/
│ └── input/ # Input files directory
└── pom.xml # Maven configuration
- Java JDK 8 or higher
- Maven 3.x
- Apache PDFBox 2.0.27 (for file reading utilities)
-
Clone the repository (if applicable):
git clone <repository-url> cd CPU-scheduling
-
Build the project using Maven:
mvn clean compile
-
Run the application:
mvn exec:java -Dexec.mainClass="com.cpuScheculing.App"Or compile and run directly:
mvn compile java -cp target/classes com.cpuScheculing.App
-
Process Input: The application reads processes from a file located at
src/main/resources/input/. Currently configured to read from a PDF file, but theFileReaderUtilcan process any text-based file. -
Process Generation: For each line in the input file:
- Process ID is assigned sequentially
- Burst time is calculated as the length of the line
- Arrival time is simulated sequentially
- Priority is calculated based on line length (shorter lines = higher priority)
-
Scheduling Simulation: Each scheduling algorithm processes the list of processes and calculates:
- Start time for each process
- Finish/completion time
- Waiting time
- Turnaround time
- Average waiting time
- Average turnaround time
-
Comparison: The application compares all algorithms and identifies the best one based on the lowest average waiting time.
The application provides detailed output for each scheduling algorithm, including:
- Individual process execution details (start time, finish time, waiting time, turnaround time)
- Average waiting time and average turnaround time for each algorithm
- A comparison table showing all algorithms side-by-side
- The best algorithm recommendation based on performance metrics
FCFS Scheduling:
Process Start Time Finish Time Waiting Time Turnaround Time
...
Comparison of Algorithms:
Algorithm Average Waiting Time Average Turnaround Time
FCFS X.XX X.XX
Non-Preemptive SJF X.XX X.XX
Preemptive SJF X.XX X.XX
Priority Scheduling X.XX X.XX
Round Robin X.XX X.XX
Best Algorithm: [Algorithm Name] (Lower Average Waiting Time)
You can modify the following parameters in App.java:
filePath: Path to the input file containing process datamaxProcesses: Maximum number of processes to read from the file- Time quantum for Round Robin scheduling (currently set to 2)
Contributions are welcome! Feel free to:
- Add new scheduling algorithms
- Improve the file reading utilities
- Enhance the comparison and visualization features
- Fix bugs or improve code quality
This project is open source and available for educational purposes.
CPU Scheduling Algorithms Simulator - Educational Project