(Open in Desktop/Laptop/Big Screen for better result.)
Title: Write a program to implement First Come First Serve Scheduling Algorithm.
Calculate average waiting time, average turnaround time and throughput. (Given the
list of Processes, their CPU burst times).
Calculate average waiting time, average turnaround time and throughput. (Given the
list of Processes, their CPU burst times).
Theory:
➤ FCFS Scheduling algorithm:
First Come First Serve (FCFS) is an operating system scheduling algorithm that automatically executes queued requests and processes in order of their arrival. It is the easiest and simplest CPU scheduling algorithm. In this type of algorithm, processes which requests the CPU first get the CPU allocation first. This is managed with a FIFO queue. The full form of FCFS is First Come First Serve.
➤ Program for FCFS Scheduling:
#include <stdio.h>
// Function to find the waiting time for all processes
int waitingtime(int proc[], int n,
int burst_time[], int wait_time[]){
int burst_time[], int wait_time[]){
// waiting time for first process is 0
wait_time[0] = 0;
// calculating waiting time
for (int i = 1; i < n ; i++ )
wait_time[i] = burst_time[i-1] + wait_time[i-1] ;
return 0;
}
// Function to calculate turn around time
int turnaroundtime( int proc[], int n,
int burst_time[], int wait_time[], int tat[]){
// calculating turnaround time by adding
// burst_time[i] + wait_time[i]
int i;
for ( i = 0; i < n ; i++)
tat[i] = burst_time[i] + wait_time[i];
return 0;
}
//Function to calculate average time
int avgtime( int proc[], int n, int burst_time[]){
int wait_time[n], tat[n], total_wt = 0, total_tat = 0;
int i;
//Function to find waiting time of all processes
waitingtime(proc, n, burst_time, wait_time);
//Function to find turn around time for all processes
turnaroundtime(proc, n, burst_time, wait_time, tat);
//Display processes along with all details
printf("Processes Burst Waiting Turn around \n");
// Calculate total waiting time and total turn around time
for ( i=0; i<n; i++) {
total_wt = total_wt + wait_time[i];
total_tat = total_tat + tat[i];
printf(" %d\t %d\t\t %d \t%d\n", i+1, burst_time[i], wait_time[i], tat[i]);
}
printf("Average waiting time = %f\n", (float)total_wt / (float)n);
printf("Average turn around time = %f\n", (float)total_tat / (float)n);
return 0;
}
// main function
int main(){
//process id's
int proc[] = { 1, 2, 3};
int n = sizeof proc / sizeof proc[0];
//Burst time of all processes
int burst_time[] = {5, 8, 12};
avgtime(proc, n, burst_time);
return 0;
}
Observation / Output:
Take any 1 problem, and Calculate average waiting time, average turnaround time and throughput.
Note that in table its order of arrival and not Arrival time Assume here the arrival time is of
all is process is same i.e. 0.
➼ Average waiting time:
First calculate waiting time of each process Therefore,
Waiting time of P2 = 0;
Waiting time of P2 = 0;
Waiting time of P3 = 3;
Waiting time of P1 = 6;
Average Waiting time = (0+3+6)/3 = 3.
Average Waiting time = (0+3+6)/3 = 3.
➼ Average turnaround time:
Turnaround time of P2 = 3;
Turnaround time of P3 = 6;
Turnaround time of P1 = 21;
Average Turnaround time = (3+6+21)/3 = 10.
➼Throughtput = 3/21 = 1/7.
Conclusion:
➼ Advantage:
• The simplest form of a CPU scheduling algorithm.
• Easy to program.
• First come first served.
➼ Disadvantage:
• Allocated to the CPU, it will never release the CPU until it finishes executing.
• The Average Waiting Time is high.
• Short processes that are at the back of the queue have to wait for the long process
at the front to finish.
• Not an ideal technique for time-sharing systems.
• Because of its simplicity, FCFS is not very efficient.