Ex No 3A Algorithm For Fcfs
Ex No 3A Algorithm For Fcfs
a) Waiting time for process(n)= waiting time of process (n-1) + Burst time of
process(n-1)
b) Turnaround time for Process(n)= waiting time of Process(n)+ Burst time for
process(n)
6. Calculate
a) Average waiting time = Total waiting Time / Number of process
b) Average Turnaround time = Total Turnaround Time / Number of process
Ex.No 3d
Algorithm for RR
1. Accept the number of processes in the ready Queue and time quantum (or) time slice
2. For each process in the ready Q, assign the process id and accept the CPU burst time
3. Calculate the no. of time slices for each process where
No. of time slice for process(n) = burst time process(n)/time slice
4. If the burst time is less than the time slice then the no. of time slices =1.
5. Consider the ready queue is a circular Q, calculate
(a) Waiting time for process(n) = waiting time of process(n-1)+ burst time of
process(n-1 ) + the time difference in getting the CPU from process(n-1)
(b) Turn around time for process(n) = waiting time of process(n) + burst time of
process(n)+ the time difference in getting CPU from process(n).
6. Calculate
(a) Average waiting time = Total waiting Time / Number of process
(b) Average Turnaround time = Total Turnaround Time / Number of process
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int tq,ct[10],s=0,totwt=0,turnt=0,status=0;
int jremaint[10],pburst[10],wt[10],pt[10],n,i;
2
clrscr();
printf("\n CPU-SCHEDULING by ROUND ROBIN\n");
printf(" .............................\n\n");
printf("Enter the no of process ");
scanf("%d",&n);
printf("\nEnter the process burst time\n");
for(i=0;i<n;i++)
{
scanf("%d",&pburst[i]);
jremaint[i]=pburst[i];
pt[i]=wt[i]=0;
}
printf("Enter the Time Quantum ");
scanf("%d",&tq);
do
{
status=0;
for(i=0;i<n;i++)
{
if(jremaint[i]!=0)
{
wt[i]+=(s-pt[i]);
if(jremaint[i]<tq)
{
pt[i]=s=s+jremaint[i];
jremaint[i]=0;
}
else
{
3
pt[i]=s;
s=s+tq;
jremaint[i]-=tq;
}
if(jremaint[i]==0)
ct[i]=s;
status=1;
}
}
}
while(status);
printf("\nProcess BurstTime WaitingTime TurnArroundTime \n");
for(i=0;i<n;i++)
{
printf("\n%d\t%d\t %d\t\t%d\n",i+1,pburst[i],wt[i],wt[i]+pburst[i]);
totwt+=wt[i];
turnt+=(wt[i]+pburst[i]);
}
printf("\nTotal waiting time =%d\n",totwt);
printf("\nAverage waiting time =%f \n",(float)totwt/n);
printf("\nTotal turn around time =%d\n",turnt);
printf("\nAverage turnaround time =%f\n",(float)turnt/n);
getch();
}
OUTPUT:
.............................
18
23
19
25
14
17
15
19
17
20