LAB 4-Python Programs-Round Robin&SRTF
LAB 4-Python Programs-Round Robin&SRTF
rem_bt = [0] * n
for i in range(n):
rem_bt[i] = bt[i]
t = 0 # Current time
# Keep traversing processes in round robin manner until all of them are not done.
while(1):
done = True
for i in range(n):
# If burst time of a process is greater than 0 then only need to process further
# Increase the value of t i.e. shows how much time a process has been processed
t += quantum
rem_bt[i] -= quantum
# If burst time is smaller than or equal to quantum. Last cycle for this process
else:
# Increase the value of t i.e. shows how much time a process has been processed
t = t + rem_bt[i]
wt[i] = t - bt[i]
# As the process gets fully executed make its remaining burst time = 0
rem_bt[i] = 0
for i in range(n):
wt = [0] * n
tat = [0] * n
total_wt = 0
total_tat = 0
for i in range(n):
# Driver code
if __name__ == "__main__":
# Process id's
proc = [1, 2, 3]
n=3
burst_time = [10, 5, 8]
# Time quantum
quantum = 2
rt = [0] * n
for i in range(n):
rt[i] = processes[i][1]
complete = 0
t=0
minm = 999999999
short = 0
check = False
# Find process with minimum remaining time among the processes that arrives till the current time`
for j in range(n):
minm = rt[j]
short = j
check = True
if (check == False):
t += 1
continue
rt[short] -= 1
# Update minimum
minm = rt[short]
if (minm == 0):
minm = 999999999
if (rt[short] == 0):
# Increment complete
complete += 1
check = False
fint = t + 1
wt[short] = 0
# Increment time
t += 1
for i in range(n):
wt = [0] * n
tat = [0] * n
findWaitingTime(processes, n, wt)
total_wt = 0
total_tat = 0
for i in range(n):
processes[i][1], "\t\t",
# Driver code
if __name__ =="__main__":
# Process id's
n=4
findavgTime(proc, n)