This project implements two CPU scheduling algorithms: First Come First Serve (FCFS) and Shortest Job First (SJF). The program takes input parameters such as the number of processes, arrival time, and burst time for each process. It then computes the waiting time, turnaround time, average waiting time, and average turnaround time for each process.
- First Come First Serve (FCFS): Processes are executed in the order they arrive.
- Shortest Job First (SJF): Processes with the shortest burst time are executed first, allowing for efficient resource utilization.
The program prompts the user to choose an algorithm and input the following parameters:
- Number of processes
- Arrival time and burst time for each process
-
Clone the repository:
git clone https://github.com/your_username/cpu-scheduling-algorithm.git
-
Compile the program:
g++ main.cpp ProcessScheduler.cpp Process.cpp -o scheduler
-
Run the program:
./scheduler
- Choose an algorithm: FCFS or SJF.
- Enter the number of processes.
- Enter the arrival time and burst time for each process.
- View the scheduling results, including waiting time, turnaround time, and Gantt chart.
Choose an algorithm:
[1] - First Come First Serve (FCFS)
[2] - Shortest Job First (SJF)
> 2
Enter number of processes:
> 4
Enter the arrival time and burst time for Process 1:
Arrival Time: > 0
Burst Time: > 7
Enter the arrival time and burst time for Process 2:
Arrival Time: > 2
Burst Time: > 4
Enter the arrival time and burst time for Process 3:
Arrival Time: > 4
Burst Time: > 1
Enter the arrival time and burst time for Process 4:
Arrival Time: > 5
Burst Time: > 4
PROCESS ARRIVAL TIME BURST TIME WAITING TIME TURNAROUND TIME
P1 0 7 0 7
P3 1 4 3 4
P2 2 4 6 10
P4 4 5 7 12
Average Waiting Time: 4
Average Turnaround Time: 8
GANTT CHART
|P1|****P3****|****P2****|******P4******|
0 7 11 15 20