Advertisement
Guest User

RR

a guest
Nov 12th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. def findWaitingTime(processes, n, bt, wt, quantum):
  2. rem_bt = [0] * n
  3. for i in range(n):
  4. rem_bt[i] = bt[i]
  5. t = 0
  6.  
  7. while(1):
  8. done = True
  9. for i in range(n):
  10. if (rem_bt[i] > 0) :
  11. done = False
  12. if (rem_bt[i] > quantum) :
  13. t += quantum
  14. rem_bt[i] -= quantum
  15. else:
  16. t = t + rem_bt[i]
  17. wt[i] = t - bt[i]
  18. rem_bt[i] = 0
  19. if (done == True):
  20. break
  21.  
  22. def findTurnAroundTime(processes, n, bt, wt, tat):
  23. for i in range(n):
  24. tat[i] = bt[i] + wt[i]
  25.  
  26. def findavgTime(processes, n, bt, quantum):
  27. wt = [0] * n
  28. tat = [0] * n
  29.  
  30. findWaitingTime(processes, n, bt, wt, quantum)
  31. findTurnAroundTime(processes, n, bt, wt, tat)
  32. print("Processes Burst Time Waiting", "Time Turn-Around Time")
  33. total_wt = 0
  34. total_tat = 0
  35. for i in range(n):
  36. total_wt = total_wt + wt[i]
  37. total_tat = total_tat + tat[i]
  38. print(" ", i + 1, "\t\t", bt[i], "\t\t", wt[i], "\t\t", tat[i])
  39.  
  40. print("\nAverage waiting time = %.5f "%(total_wt /n) )
  41. print("Average turn around time = %.5f "% (total_tat / n))
  42.  
  43. if __name__ =="__main__":
  44. proc = [1, 2, 3]
  45. n = 3
  46. burst_time = [10, 5, 8]
  47. quantum = 2;
  48. findavgTime(proc, n, burst_time, quantum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement