-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRR_Mod1.c
94 lines (94 loc) · 1.8 KB
/
RR_Mod1.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
#include<stdio.h>
struct process {
int pno,bt,cbt,tat,wt,at;
};
void main()
{
int n,i,tq,j;
float ttat,twt,atwt,atat;
printf("Enter the number of process : ");
scanf("%d",&n);
struct process p[n],temp;
printf("Enter the Process no., Arrival time and Burst time of :-\n");
for(i=0;i<n;i++) {
printf("Process : ");
scanf("%d %d %d",&p[i].pno,&p[i].at,&p[i].bt);
p[i].cbt=p[i].bt;
}
printf("Enter the time quantum : ");
scanf("%d",&tq);
for(i=0;i<n-1;i++) {
for(j=i+1;j<n;j++) {
if(p[i].at>p[j].at) {
temp=p[i];
p[i]=p[j];
p[j]=temp;
}
}
}
printf("GANTT CHART\n0");
int time=0,completedp=0,t,queue[20],nxt,pro;
i=0,j=0;
do {
if(p[i].bt>0 && p[i].at<=time) {
if(p[i].bt>tq) {
//queue[j]=i;
queue[j]=p[i].pno;
printf("%d P%d\n",j,queue[j]);
j++;
time=time+tq;
p[i].bt-=tq;
//printf(" P%d %d",p[i].pno,time);
pro=i;
for (t=j; t<time; t++) {
if (p[(pro+1)%n].at<=t) {
//queue[j]=(i+1)%n;
queue[j]=p[(pro+1)%n].pno;
printf("%d iP%d %d %d %d\n",j,queue[j],i,pro,t);
j++;
pro++;
}
else {
//queue[j]=i;
queue[j]=p[i].pno;
printf("%d eP%d %d %d %d\n",j,queue[j],i,pro,t);
j++;
pro++;
}
}
}
else {
time=time+p[i].bt;
p[i].tat=time;
p[i].wt=p[i].tat-p[i].cbt;
p[i].bt=0;
completedp++;
//printf(" P%d %d",p[i].pno,time);
if(completedp==n) {
break;
}
}
}
else {
time=p[i].at;
printf(" IDEAL %d",time);
}
if(i==n-1) {
i=0;
}
else {
i++;
}
scanf("%d",&nxt);
}while(nxt==1);
printf("\nProcess no.\tBurst time\tTurnaround time\tWaiting time\n");
for(i=0;i<n;i++) {
printf("P%d\t\t%d\t\t%d\t\t%d\n",p[i].pno,p[i].cbt,p[i].tat,p[i].wt);
}
ttat=p[n-1].tat;
twt=p[n-1].wt;
atat=ttat/n;
atwt=twt/n;
printf("Average Turnaround time = %f\n",atat);
printf("Average Waiting time = %f\n",atwt);
}