A comprehensive Java Swing application that simulates and visualizes various CPU scheduling algorithms used in operating systems. This educational tool helps students and professionals understand how different scheduling algorithms work and compare their performance.
- Multiple Scheduling Algorithms: Supports four popular CPU scheduling algorithms
- Interactive GUI: User-friendly graphical interface built with Java Swing
- Visual Gantt Chart: Real-time visualization of process execution timeline
- Performance Metrics: Calculates and displays average waiting time and turnaround time
- Flexible Process Configuration: Support for arrival times and priority values
- Data Tables: Clear input and results display in tabular format
- Keyboard Shortcuts: Enhanced user experience with keyboard shortcuts
- Non-preemptive scheduling algorithm
- Processes are executed in the order of their arrival
- Simple but can lead to convoy effect
- Non-preemptive scheduling algorithm
- Selects the process with the shortest burst time
- Optimal for minimizing average waiting time
- Non-preemptive scheduling algorithm
- Processes are executed based on priority (lower number = higher priority)
- Can lead to starvation of low-priority processes
- Preemptive scheduling algorithm
- Each process gets a fixed time quantum
- Provides fair CPU allocation and good response time
- Java Development Kit (JDK) 8 or higher
- Any Java IDE (Eclipse, IntelliJ IDEA, NetBeans) or command line
-
Clone the repository
git clone https://github.com/yourusername/cpu-scheduling-simulator.git cd cpu-scheduling-simulator -
Compile the project
javac -d bin src/algorithms/*.java -
Run the application
java -cp bin algorithms.SchedulingGUI
- Import the project into your preferred Java IDE
- Ensure the
algorithmspackage is properly configured - Run the
SchedulingGUI.javaclass
- Process ID: Enter a unique identifier for the process
- Burst Time: Specify the CPU time required by the process
- Priority (Optional): Enable checkbox and enter priority value (for Priority Scheduling)
- Arrival Time (Optional): Enable checkbox and enter when the process arrives
- Click "Add Process" or press Enter to add the process
- Select the desired scheduling algorithm from the dropdown menu
- For Round Robin, specify the Time Quantum value
- Click "Calculate" or press Ctrl+Enter to run the simulation
- View results in the tables and Gantt chart
- Enter: Add process (when in input fields)
- Ctrl+Enter: Calculate/Run simulation
- Escape: Clear all data
- Process: Process identifier
- Arrival Time: When the process arrives in the ready queue
- Burst Time: CPU time required by the process
- Start Time: When the process first gets CPU
- Completion Time: When the process finishes execution
- Turnaround Time: Total time from arrival to completion
- Waiting Time: Time spent waiting in the ready queue
- Average Waiting Time: Mean time processes wait before execution
- Average Turnaround Time: Mean total time from arrival to completion
Visual representation showing:
- Process execution timeline
- Color-coded process blocks
- Time markers for easy reference
- Round Robin shows preemptive switching
src/
βββ algorithms/
βββ SchedulingGUI.java # Main GUI application
βββ Process.java # Process data structure
βββ FCFSScheduling.java # First Come First Serve implementation
βββ SJFScheduling.java # Shortest Job First implementation
βββ PriorityScheduling.java # Priority Scheduling implementation
βββ RoundRobinScheduling.java # Round Robin implementation
| Process | Arrival Time | Burst Time | Priority |
|---|---|---|---|
| P1 | 0 | 8 | 3 |
| P2 | 1 | 4 | 1 |
| P3 | 2 | 9 | 4 |
| P4 | 3 | 5 | 2 |
- Execution Order: P2 β P4 β P1 β P3
- Average Waiting Time: Calculated based on algorithm
- Average Turnaround Time: Displayed in the application
- Clean Design: Modern, intuitive interface with proper color coding
- Responsive Layout: Tables and charts adapt to window size
- Error Handling: Input validation with helpful error messages
- Real-time Updates: Immediate feedback on user actions
- Accurate Calculations: Precise implementation of scheduling algorithms
- Edge Case Handling: Proper handling of arrival times and priorities
- Performance Optimized: Efficient algorithms for large process sets
- Data Validation: Input validation to prevent errors
This simulator is perfect for:
- Operating Systems Courses: Hands-on learning of CPU scheduling
- Algorithm Comparison: Side-by-side analysis of different approaches
- Performance Analysis: Understanding trade-offs between algorithms
- Visual Learning: Gantt charts make abstract concepts concrete
Contributions are welcome! Here are ways you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Add more scheduling algorithms (SRTF, Multilevel Queue, etc.)
- Implement preemptive versions of existing algorithms
- Add export functionality for results
- Enhance the UI with more visualization options
- Add unit tests for algorithm implementations
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by operating systems textbooks and coursework
- Built with Java Swing for cross-platform compatibility
- Designed for educational purposes in computer science curriculum
If you encounter any issues or have questions:
- Check the Issues section
- Create a new issue with detailed description
- Contact the maintainer through GitHub
Happy Learning! π
This project is designed to make CPU scheduling concepts accessible and engaging for learners at all levels.