Ex. No.: 5(a)
|
SIMULATION
OF CPU SCHEDULING ALGORITHMS - FCFS
|
AIM
To simulate CPU scheduling, using First Come First Serve(FCFS) Scheduling algorithms.
Description:
FCFS is a non preemptive scheduling in which the processes are dispatched according to their arrival time in the ready queue. Once the process has the CPU it runs to completion. It depicts the order in which the processes are executed, calculates the turnaround time and average waiting time of the processes based on the arrival time for the FCFS scheduling.
Algorithm:
1. Start of algorithm.
2. Declare the required variables
3. Get the process name, and burst time for each process.
4. Calculate the average waiting time and average turn around time using the following formulas.
Average Waiting Time = (wt1+wt2+…+wtn) / n where
Average turn around time = ((wt1+wt2+…+wtn) + (bt1+bt2+…+btn)) / n
5. Print the Process name, average waiting time and average turnaround time for each process.
6. Terminate the program.
Average waiting time and average turn around time calculation:
Average Waiting Time = (wt1+wt2+…+wtn)/n where
wt - waiting time of each process in the ready queue. Wt is the
previous process’s arrival time and burst time.
n - Number of processes.
average turn around time= ((wt1+wt2+…+wtn)+ (bt1+bt2+…+btn))/n where
wt - waiting time of each process in the ready queue
bt – Burst time of each process.
n - Number of processes.
Program : To implement First Come First Serve Algorithm*/
#include<stdio.h>
main()
{
int n,i,j=0,avgw=0,avgt=0;
int burst[10],wait[10];
printf("\nProcess Scheduling(FCFS) :\n");
printf("\nEnter the number of process : ");
scanf("%d",&n);
printf("Enter the Burst time : \n");
for(i=0;i<n;i++)
{
printf("P%d : ",i+1);
scanf("%d",&burst[i]);
}
printf("\nWaiting time | Turn around time \n");
for(i=0;i<n;i++)
{
wait[i] = j;
j = burst[i] + j;
printf("\np%d : %d\t\t%d",i+1,wait[i],wait[i]+burst[i]);
avgw+=wait[i];
avgt+=wait[i]+burst[i];
}
printf("\n\n");
printf("Average waiting time : %f\nAverage Turn around time : %f\n\n"
,avgw/n,avgt/n);
}
/*OUTPUT:
======
Enter the number of processes:
3
Enter the burst time:
P1:3
P2:3
P3:23
Waiting time | Turn around time
p1:0 3
p2:3 6
p3:6 29
Average waiting time is:3
Average turn around time is:12*/
fadoo posts
ReplyDeleteThanks for nice post.C programming details here
ReplyDelete