-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.Round Robin.py
44 lines (43 loc) · 1.41 KB
/
4.Round Robin.py
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
def findWaitingTime(processes, n, bt,wt, quantum):
rem_bt = [0] * n
for i in range(n):
rem_bt[i] = bt[i]
t = 0
while(1):
done = True
for i in range(n):
if (rem_bt[i] > 0) :
done = False
if (rem_bt[i] > quantum) :
t += quantum
rem_bt[i] -= quantum
else:
t = t + rem_bt[i]
wt[i] = t - bt[i]
rem_bt[i] = 0
if (done == True):
break
def findTurnAroundTime(processes, n, bt, wt, tat):
for i in range(n):
tat[i] = bt[i] + wt[i]
def findavgTime(processes, n, bt, quantum):
wt = [0] * n
tat = [0] * n
findWaitingTime(processes, n, bt,wt, quantum)
findTurnAroundTime(processes, n, bt,wt, tat)
print("Processes Burst Time Waiting","Time Turn-Around Time")
total_wt = 0
total_tat = 0
for i in range(n):
total_wt = total_wt + wt[i]
total_tat = total_tat + tat[i]
print(" ", i + 1, "\t\t", bt[i],"\t\t", wt[i], "\t\t", tat[i])
print("\nAverage waiting time = %.5f "%(total_wt /n) )
print("Average turn around time = %.5f "% (total_tat / n))
# Driver code
if __name__ =="__main__":
proc = [1,2,3,4,5,6]
n = 5
burst_time = [4,2,5,3,4,1]
quantum = 2;
findavgTime(proc, n, burst_time, quantum)