akbarbasya26

FIFO.py

Jan 6th, 2021
774
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def findWaitingTime(processes, n, bt, wt, quantum):
  2.     wt[0] = 0
  3.     for i in range(1, n ):
  4.         wt[i] = bt[i - 1] + wt[i - 1] + quantum
  5. def findTurnAroundTime(processes, n, bt, wt, tat):
  6.     for i in range(n):
  7.         tat[i] = bt[i] + wt[i]
  8. def findavgTime( processes, n, bt, quantum):
  9.     wt = [0] * n
  10.     tat = [0] * n
  11.     total_wt = 0
  12.     total_tat = 0
  13.     print ("Contoh  First Come First Serve ")
  14.     print ("Waiting Time = Turn Around Time - Burst Time ")
  15.     findWaitingTime(processes, n, bt, wt, quantum)
  16.     findTurnAroundTime(processes, n, bt, wt, tat)
  17.     print( "Processes Burst time " +
  18.                 " Waiting time " +
  19.                 " Turn around time")
  20.     for i in range(n):
  21.         total_wt = total_wt + wt[i]
  22.         total_tat = total_tat + tat[i]
  23.         print(" " + str(i + 1) + "\t\t" +
  24.                     str(bt[i]) + "\t " +
  25.                     str(wt[i]) + "\t\t " +
  26.                     str(tat[i]))
  27.     print ("quantum time = ", quantum)
  28.     print( "Average waiting time = "+ str(total_wt / n))
  29.     print("Average turn around time = "+ str(total_tat / n))
  30. if __name__ =="__main__":
  31.     processes = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  32.     n = len(processes)
  33.     burst_time = [46, 35, 46*46, 15, 20, 46+46, 5, 46+14, (46+(2*46))-3, 12]
  34.     quantum = 4;
  35.     findavgTime(processes, n, burst_time,quantum)
  36.  
RAW Paste Data