《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.4 KiB

  1. # 理解调度算法
  2. ## 实现3种调度算法(SJF,FIFO,RR),可基于python, ruby, C, C++,LISP等)模拟实现,并给出测试。请参考scheduler-homework.py代码或独自实现。
  3. 最后统计采用不同调度算法的每个任务的相关时间和总体的平均时间:
  4.  - turnaround time 周转时间
  5.  - response time 响应时间
  6.  - wait time 等待时间
  7. ### 对模拟环境的抽象
  8. - 任务/进程,及其执行时间
  9. Job 0 (length = 1)
  10. Job 1 (length = 4)
  11. Job 2 (length = 7)
  12. - 何时切换?
  13. - 如何统计?
  14. ### 执行结果
  15. 采用FIFO调度算法
  16. ```
  17. ./scheduler-homework.py -p FIFO
  18. ARG policy FIFO
  19. ARG jobs 3
  20. ARG maxlen 10
  21. ARG seed 0
  22. Here is the job list, with the run time of each job:
  23. Job 0 ( length = 9 )
  24. Job 1 ( length = 8 )
  25. Job 2 ( length = 5 )
  26. ** Solutions **
  27. Execution trace:
  28. [ time 0 ] Run job 0 for 9.00 secs ( DONE at 9.00 )
  29. [ time 9 ] Run job 1 for 8.00 secs ( DONE at 17.00 )
  30. [ time 17 ] Run job 2 for 5.00 secs ( DONE at 22.00 )
  31. Final statistics:
  32. Job 0 -- Response: 0.00 Turnaround 9.00 Wait 0.00
  33. Job 1 -- Response: 9.00 Turnaround 17.00 Wait 9.00
  34. Job 2 -- Response: 17.00 Turnaround 22.00 Wait 17.00
  35. Average -- Response: 8.67 Turnaround 16.00 Wait 8.67
  36. ```
  37. 采用SJF调度算法
  38. ```
  39. ./scheduler-homework.py -p SJF
  40. ARG policy SJF
  41. ARG jobs 3
  42. ARG maxlen 10
  43. ARG seed 0
  44. Here is the job list, with the run time of each job:
  45. Job 0 ( length = 9 )
  46. Job 1 ( length = 8 )
  47. Job 2 ( length = 5 )
  48. ** Solutions **
  49. Execution trace:
  50. [ time 0 ] Run job 2 for 5.00 secs ( DONE at 5.00 )
  51. [ time 5 ] Run job 1 for 8.00 secs ( DONE at 13.00 )
  52. [ time 13 ] Run job 0 for 9.00 secs ( DONE at 22.00 )
  53. Final statistics:
  54. Job 2 -- Response: 0.00 Turnaround 5.00 Wait 0.00
  55. Job 1 -- Response: 5.00 Turnaround 13.00 Wait 5.00
  56. Job 0 -- Response: 13.00 Turnaround 22.00 Wait 13.00
  57. Average -- Response: 6.00 Turnaround 13.33 Wait 6.00
  58. ```
  59. 采用RR调度算法
  60. ```
  61. ./scheduler-homework.py -p RR
  62. ARG policy RR
  63. ARG jobs 3
  64. ARG maxlen 10
  65. ARG seed 0
  66. Here is the job list, with the run time of each job:
  67. Job 0 ( length = 9 )
  68. Job 1 ( length = 8 )
  69. Job 2 ( length = 5 )
  70. ** Solutions **
  71. Execution trace:
  72. [ time 0 ] Run job 0 for 1.00 secs
  73. [ time 1 ] Run job 1 for 1.00 secs
  74. [ time 2 ] Run job 2 for 1.00 secs
  75. [ time 3 ] Run job 0 for 1.00 secs
  76. [ time 4 ] Run job 1 for 1.00 secs
  77. [ time 5 ] Run job 2 for 1.00 secs
  78. [ time 6 ] Run job 0 for 1.00 secs
  79. [ time 7 ] Run job 1 for 1.00 secs
  80. [ time 8 ] Run job 2 for 1.00 secs
  81. [ time 9 ] Run job 0 for 1.00 secs
  82. [ time 10 ] Run job 1 for 1.00 secs
  83. [ time 11 ] Run job 2 for 1.00 secs
  84. [ time 12 ] Run job 0 for 1.00 secs
  85. [ time 13 ] Run job 1 for 1.00 secs
  86. [ time 14 ] Run job 2 for 1.00 secs ( DONE at 15.00 )
  87. [ time 15 ] Run job 0 for 1.00 secs
  88. [ time 16 ] Run job 1 for 1.00 secs
  89. [ time 17 ] Run job 0 for 1.00 secs
  90. [ time 18 ] Run job 1 for 1.00 secs
  91. [ time 19 ] Run job 0 for 1.00 secs
  92. [ time 20 ] Run job 1 for 1.00 secs ( DONE at 21.00 )
  93. [ time 21 ] Run job 0 for 1.00 secs ( DONE at 22.00 )
  94. Final statistics:
  95. Job 0 -- Response: 0.00 Turnaround 22.00 Wait 13.00
  96. Job 1 -- Response: 1.00 Turnaround 21.00 Wait 13.00
  97. Job 2 -- Response: 2.00 Turnaround 15.00 Wait 10.00
  98. Average -- Response: 1.00 Turnaround 19.33 Wait 12.00
  99. ```