Skip to content

Naveenramgeek/CPU-scheduling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPU Scheduling Algorithms Simulator

A Java-based simulation tool that implements and compares multiple CPU scheduling algorithms. This project demonstrates various process scheduling strategies and their performance metrics.

Features

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

Project Structure

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

Requirements

  • Java JDK 8 or higher
  • Maven 3.x

Dependencies

  • Apache PDFBox 2.0.27 (for file reading utilities)

How to Run

  1. Clone the repository (if applicable):

    git clone <repository-url>
    cd CPU-scheduling
  2. Build the project using Maven:

    mvn clean compile
  3. 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

How It Works

  1. Process Input: The application reads processes from a file located at src/main/resources/input/. Currently configured to read from a PDF file, but the FileReaderUtil can process any text-based file.

  2. 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)
  3. 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
  4. Comparison: The application compares all algorithms and identifies the best one based on the lowest average waiting time.

Output

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

Example Output

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)

Configuration

You can modify the following parameters in App.java:

  • filePath: Path to the input file containing process data
  • maxProcesses: Maximum number of processes to read from the file
  • Time quantum for Round Robin scheduling (currently set to 2)

Contributing

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

License

This project is open source and available for educational purposes.

Author

CPU Scheduling Algorithms Simulator - Educational Project

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages