-
Notifications
You must be signed in to change notification settings - Fork 0
/
RIO.py
146 lines (120 loc) · 2.93 KB
/
RIO.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import sys
def disp(x, s):
sys.stdout.write("\033[;1m") #BOLD headings
print s
sys.stdout.write("\033[0;0m") #RESET to normal(default)
for i in range(count):
print 'P' + str(i+1) + '\t' + str(x[i])
def fileRead(arriv, burst, count):
file = open("rr.txt", "r")
count = int(file.readline())
for i in range(count):
arriv.insert(i, int(file.readline()))
for i in range(count):
burst.insert(i, int(file.readline()))
return count
def cal(line):
i = 0
n = 0
qt = []
io = []
iow = []
copy = []
line = arriv[0]
for i in range(count):
qt.insert(i, QT)
io.insert(i, IO)
iow.insert(i, 0)
copy.insert(i, burst[i])
while n != count:
i = 0
for i in range(count):
if copy[i] != 999999:
if copy[i] <= qt[i]:
if i%2 != RE: #I/O wale process
if copy[i] <= io[i] & iow[i] <= line:
line += copy[i]
qt[i] = 999999;
io[i] = 999999;
iow[i] = 999999;
copy[i] = 999999;
end.insert(i, line)
elif copy[i] > io[i] & iow[i] <= line:
line += io[i]
qt[i] -= io[i]
iow[i] = line + IOW
copy[i] -= io[i]
else:
line += copy[i]
qt[i] = 999999;
#io[i] = 999999;
copy[i] = 999999;
end.insert(i, line)
elif copy[i] > qt[i]:
if i%2 != RE: #I/O wale process
if copy[i] <= io[i] & iow[i] <= line:
line += qt[i]
io[i] -= qt[i]
copy[i] -= qt[i]
elif copy[i] > io[i] & iow[i] <= line:
if qt[i] >= io[i]:
line += io[i]
qt[i] -= io[i]
iow[i] = line + IOW
copy[i] -= io[i]
elif qt[i] < io[i]:
line += qt[i]
io[i] -= qt[i]
copy[i] -= qt[i]
else:
line += QT
copy[i] -= QT
if qt[i] == 0:
qt[i] = QT;
if io[i] == 0:
io[i] = IO;
if copy[i] == 999999:
n += 1
print copy, qt, io
print iow
#print i, copy
def waiting(sum):
sum = 0
for i in range(count):
wait.insert(i, (turn[i] - burst[i]))
sum += wait[i]
disp(wait, '\nWaiting Time')
return sum
def turnaround(sum):
sum = 0
for i in range(count):
turn.insert(i, (end[i] - arriv[i]))
sum += turn[i]
disp(turn, '\nTurnaround Time')
return sum
sum = 0
line = 0
count = 0
end = []
wait = []
turn = []
start = []
arriv = []
burst = []
count = fileRead(arriv, burst, count)
QT = int(input('Enter Quantum Time : '))
IO = int(input('Enter I/O Interrupt Time : '))
RE = int(input('Enter 0 for EVEN Process Interrupts or 1 for ODD : '))
IOW = int(input('Enter I/O Waiting Time : '))
disp(arriv, '\nArrival Time')
disp(burst, '\nBurst Time')
cal(line)
disp(end, '\nCompletion Time')
sum = turnaround(sum)
avg = float(sum)/count
sys.stdout.write("\033[1;33m") #setting text color to YELLOW
print '\nAverage Turnaround Time : ' + str(avg)
sum = waiting(sum)
avg = float(sum)/count
sys.stdout.write("\033[1;33m") #setting text color to YELLOW
print '\nAverage Waiting Time : ' + str(avg)