realsdx

roundrobin.py

Nov 7th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import time
  2. from multiprocessing import Process
  3.  
  4. def fun(t):
  5. time.sleep(t)
  6. burst=[8,2,6,3]
  7. burst2=[8,2,6,3]
  8. arrival=[0,1,2,3]
  9. finish=[0,0,0,0]
  10. quantum=4
  11. n=len(burst)
  12. t0=time.time()
  13.  
  14. while 1:
  15. flag=0
  16. print("burst2 is ",burst2)
  17. for i in range(0,n):
  18. t1=time.time()
  19. if arrival[i]<=(t1-t0) and burst2[i]>0:
  20. p=Process(target=fun,args=(min(burst2[i],quantum),))
  21. t2=time.time()
  22. p.start()
  23. p.join()
  24. t3=time.time()
  25. flag=1
  26. #burst[i]=burst[i]-t3+t2
  27. burst2[i]=burst2[i]-min(burst2[i],quantum)
  28. if burst2[i]==0:
  29. finish[i]=t3-t0
  30. if flag==0:
  31. break
  32. avwt=0
  33. wt=[0]*n
  34. for i in range(0,n):
  35. wt[i]=finish[i]-arrival[i]-burst[i]
  36. avwt+=(wt[i])
  37. avwt=avwt/n
  38. print("average wt is ",avwt)
Add Comment
Please, Sign In to add comment