Skip to content

Repository files navigation

CPU Scheduling Simulator

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.

🎯 Features

  • 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

πŸ”§ Supported Algorithms

1. First Come First Serve (FCFS)

  • Non-preemptive scheduling algorithm
  • Processes are executed in the order of their arrival
  • Simple but can lead to convoy effect

2. Shortest Job First (SJF)

  • Non-preemptive scheduling algorithm
  • Selects the process with the shortest burst time
  • Optimal for minimizing average waiting time

3. Priority Scheduling

  • Non-preemptive scheduling algorithm
  • Processes are executed based on priority (lower number = higher priority)
  • Can lead to starvation of low-priority processes

4. Round Robin (RR)

  • Preemptive scheduling algorithm
  • Each process gets a fixed time quantum
  • Provides fair CPU allocation and good response time

πŸš€ Getting Started

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Any Java IDE (Eclipse, IntelliJ IDEA, NetBeans) or command line

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/cpu-scheduling-simulator.git
    cd cpu-scheduling-simulator
  2. Compile the project

    javac -d bin src/algorithms/*.java
  3. Run the application

    java -cp bin algorithms.SchedulingGUI

Alternative: IDE Setup

  1. Import the project into your preferred Java IDE
  2. Ensure the algorithms package is properly configured
  3. Run the SchedulingGUI.java class

πŸ“– How to Use

Adding Processes

  1. Process ID: Enter a unique identifier for the process
  2. Burst Time: Specify the CPU time required by the process
  3. Priority (Optional): Enable checkbox and enter priority value (for Priority Scheduling)
  4. Arrival Time (Optional): Enable checkbox and enter when the process arrives
  5. Click "Add Process" or press Enter to add the process

Running Simulations

  1. Select the desired scheduling algorithm from the dropdown menu
  2. For Round Robin, specify the Time Quantum value
  3. Click "Calculate" or press Ctrl+Enter to run the simulation
  4. View results in the tables and Gantt chart

Keyboard Shortcuts

  • Enter: Add process (when in input fields)
  • Ctrl+Enter: Calculate/Run simulation
  • Escape: Clear all data

πŸ“Š Understanding the Results

Results Table

  • 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

Performance Metrics

  • Average Waiting Time: Mean time processes wait before execution
  • Average Turnaround Time: Mean total time from arrival to completion

Gantt Chart

Visual representation showing:

  • Process execution timeline
  • Color-coded process blocks
  • Time markers for easy reference
  • Round Robin shows preemptive switching

πŸ—οΈ Project Structure

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

πŸ“ Example Usage

Sample Input

Process Arrival Time Burst Time Priority
P1 0 8 3
P2 1 4 1
P3 2 9 4
P4 3 5 2

Expected Results (Priority Scheduling)

  • Execution Order: P2 β†’ P4 β†’ P1 β†’ P3
  • Average Waiting Time: Calculated based on algorithm
  • Average Turnaround Time: Displayed in the application

🎨 Features in Detail

User Interface

  • 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

Algorithm Implementation

  • 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

πŸ” Educational Benefits

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

🀝 Contributing

Contributions are welcome! Here are ways you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contribution Ideas

  • 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

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by operating systems textbooks and coursework
  • Built with Java Swing for cross-platform compatibility
  • Designed for educational purposes in computer science curriculum

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the Issues section
  2. Create a new issue with detailed description
  3. Contact the maintainer through GitHub

Happy Learning! πŸŽ“

This project is designed to make CPU scheduling concepts accessible and engaging for learners at all levels.

About

Java-based CPU scheduling simulator with GUI. Visualizes and compares FCFS, SJF, Priority, and Round Robin algorithms using real-time Gantt charts and performance metrics.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages