-
Notifications
You must be signed in to change notification settings - Fork 0
/
program.c
117 lines (79 loc) · 2.08 KB
/
program.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
#include<stdio.h>
#include<conio.h>
int main()
{
int TSlice,ProcessID[10],need[10],WaitingTime[10],tat[10],i,j,n,n1;
int BurstTime[10],flag[10],TurnAroundTime=0,twt=0;
float aWaitingTime,atat;
printf("\t\t\t\t\t\tROUND ROBIN SCHEDULING \n");
printf("\t\t\t\t\t***********************************\n");
printf("\t\t\t\t\t___________________________________\n");
printf("Enter the number of Processors : \n");
scanf("%d",&n);
n1=n;
printf("\nEnter the Timeslice : \n");
scanf("%d",&TSlice);
for(i=1;i<=n;i++)
{
printf("\t\t\t\t Enter the arrival time of process %d: ",i);
scanf("%d",&ProcessID[i]);
printf("\t\t\t\t Enter the Burst Time for the process : ");
scanf("%d",&BurstTime[i]);
need[i]=BurstTime[i];
}
for(i=1;i<=n;i++)
{
flag[i]=1;
WaitingTime[i]=0;
}
while(n!=0)
{
for(i=1;i<=n;i++)
{
if(need[i]>=TSlice)
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
WaitingTime[j]+=TSlice;
}
need[i]-=TSlice;
if(need[i]==0)
{
flag[i]=0;
n--;
}
}
else
{
for(j=1;j<=n;j++)
{
if((i!=j)&&(flag[i]==1)&&(need[j]!=0))
WaitingTime[j]+=need[i];
}
need[i]=0;
n--;
flag[i]=0;
}
}
}
for(i=1;i<=n1;i++)
{
tat[i]=WaitingTime[i]+BurstTime[i];
twt=twt+WaitingTime[i];
TurnAroundTime=TurnAroundTime+tat[i];
}
aWaitingTime=(float)twt/n1;
atat=(float)TurnAroundTime/n1;
printf("\n\n\n\t\t\t\t\t\ROUND ROBIN SCHEDULING ALGORITHM \n\n");
printf("___________________________________________________________________________________________________________________");
printf("\n\n Process \t\t Arrival time \t\tBurstTime \t\t Waiting Time \t\t TurnaroundTime \n ");
for(i=1;i<=n1;i++)
{
printf("\n%5d \t\t\t %5d \t\t\t %5d \t\t\t %5d \t\t\t %5d \n", i,ProcessID[i],BurstTime[i],WaitingTime[i],tat[i]);
}
printf("___________________________________________________________________________________________________________________");
printf("\n The average Waiting Time=4.2",aWaitingTime);
printf("\n The average Turn around Time=4.2",atat);
getch();
}