-
Notifications
You must be signed in to change notification settings - Fork 4
/
GG_OSD4.C
124 lines (97 loc) · 2.21 KB
/
GG_OSD4.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<stdio.h>
void rr(int [],int,int,int [],int [],int []);
void print(int [],int [],int [],int [],int []);
void avgwt(int [],int);
void avgtat(int [],int [],int [],int);
int bt[20],p[20],tat[20],wt[20],n,time=0,counter[20];
float avg_wt,avg_tat;
int main()
{
int i;
printf("Enter the Time Quantum: ");
scanf("%d",&time);
printf("Enter Total Number of Process:");
scanf("%d",&n);
printf("\nEnter Burst Time\n");
for(i=0;i<n;i++)
{
printf("\nP[%d]\n",i);
printf("Burst Time:");
scanf("%d",&bt[i]);
p[i]=i; //contains process number
}
for(i=0;i<n;i++)
counter[n]=0;
rr(bt,n,time,counter,tat,wt);
//sort(pr,bt,p,n);
//avgwt(bt,n);
return 0;
}
/*void avgwt(int bt[],int n)
{
int wt[20],i,j,total=0;
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=total/n;
avgtat(bt,wt,p,n) ;
}*/
/*void avgtat(int bt[],int wt[],int p[],int n)
{
int i,tat[20],total=0;
printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i]; //calculate turnaround time
total+=tat[i];
printf("\nP[%d]\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=total/n; //average turnaround time
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
}*/
void rr(int bt[],int n,int time,int counter[],int tat[],int wt[])
{
int i,sub[20],j,k=0,temp=0;
for(i=0;i<n;i++)
sub[i]=bt[i];
do
{
k=0;
for(i=0;i<n;i++)
{
if(sub[i]==0)
{
k++;
continue;
}
else if(sub[i]<time)
{
temp=temp+sub[i];
counter[i]=temp;
sub[i]=sub[i]-sub[i];
}
else
{
sub[i]=sub[i]-time;
temp=temp+time;
counter[i]=temp;
}
}
}while(k!=5);
for(i=0;i<n;i++)
wt[i]=counter[i]-bt[i];
print(p,bt,counter,tat,wt);
}
void print(int p[],int bt[],int counter[],int tat[],int wt[])
{
int i;
printf("\nProcess Number\tBurst Time\tWaiting time\tTurnaround time\n");
for(i=0;i<n;i++)
printf("%d\t\t%d\t\t%d\t\t%d\n",p[i],bt[i],wt[i],counter[i]);
}