This project is a C-based simulation of CPU scheduling algorithms. It implements three scheduling algorithms:
- First-Come, First-Served (FCFS)
- Shortest Job First (SJF)
- Round Robin (RR)
The program allows users to input details of processes, including arrival times and burst times, and calculates the waiting time, turnaround time, and completion time for each process. It also computes the average waiting and turnaround times and optionally displays a Gantt chart.
- User Input: Number of processes, arrival times, burst times, and time quantum for Round Robin.
- Scheduling Algorithms: Simulates FCFS, SJF, and Round Robin.
- Performance Metrics: Calculates waiting time, turnaround time, and average values for all processes.
- Process Visualization: Displays process details in a tabular format.
- GCC Compiler (or any C compiler)
- Basic knowledge of CPU scheduling algorithms
$ git clone https://github.com/stephenombuya/CPU-Scheduling-Simulator
$ cd cpu-scheduling-simulator
$ gcc cpu_scheduling.c -o cpu_scheduling
$ ./cpu_scheduling
The program prompts for the following inputs:
- Number of Processes: Total number of processes to schedule.
- Process Details: Arrival time and burst time for each process.
- Scheduling Algorithm: Choice of FCFS, SJF, or Round Robin.
- Time Quantum: Required only for Round Robin.
The program displays the following:
- Process ID, Arrival Time, Burst Time, Waiting Time, Turnaround Time, and Completion Time.
- Average Waiting Time and Turnaround Time.
Example Output:
Choose the scheduling algorithm:
1. FCFS
2. SJF
3. Round Robin
Choice: 1
Process Arrival Burst Waiting Turnaround Completion
P1 0 5 0 5 5
P2 2 3 3 6 8
P3 4 8 4 12 16
Average Waiting Time: 2.33
Average Turnaround Time: 7.67
- Processes are scheduled in the order of their arrival times.
- Non-preemptive algorithm.
- Processes with the shortest burst times are scheduled first.
- Non-preemptive algorithm.
- Processes are executed in a cyclic order with a fixed time quantum.
- Preemptive algorithm.
- Process Struct: Represents a process with attributes like
id
,arrival_time
,burst_time
,remaining_time
, etc. - Main Function: Handles user input and algorithm selection.
- Helper Functions:
fcfs()
: Implements First-Come, First-Served scheduling.sjf()
: Implements Shortest Job First scheduling.round_robin()
: Implements Round Robin scheduling.calculate_average_times()
: Calculates average waiting and turnaround times.
You can extend the project to:
- Add support for additional algorithms like Priority Scheduling or Multilevel Queue.
- Include a Gantt chart for visualization.
- Improve the user interface.
Feel free to fork the repository, create a new branch, and submit a pull request for improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE
file for details.