《操作系统》的实验代码。
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.

86 lines
1.8 KiB

  1. 设计一个简化的进程管理子系统,可以管理并调度如下简化进程.给出了参考代码
  2. ### 进程的状态
  3. - RUNNING - 进程正在使用CPU
  4. - READY - 进程可使用CPU
  5. - DONE - 进程结束
  6. ### 进程的行为
  7. - 使用CPU,
  8. - 发出YIELD请求,放弃使用CPU
  9. ### 进程调度
  10. - 使用FIFO/FCFS:先来先服务
  11. ### 关键模拟变量
  12. - 进程列表:描述了进程的行为特征:(1)使用CPU ;(2)等待I/O
  13. ```
  14. -l PROCESS_LIST, --processlist= X1:Y1,X2:Y2,...
  15. X 是进程的执行指令数;
  16. Y是执行CPU的比例(0..100) ,如果是100,表示不会发出yield操作
  17. ```
  18. - 进程切换行为:系统决定何时(when)切换进程:进程结束或进程发出yield请求
  19. ### 进程执行
  20. ```
  21. instruction_to_execute = self.proc_info[self.curr_proc][PROC_CODE].pop(0)
  22. ```
  23. ### 执行实例
  24. #### 例1
  25. ```
  26. $./process-simulation.py -l 5:50
  27. Process 0
  28. yld
  29. yld
  30. cpu
  31. cpu
  32. yld
  33. Important behaviors:
  34. System will switch when the current process is FINISHED or ISSUES AN YIELD
  35. Time PID: 0
  36. 1 RUN:yld
  37. 2 RUN:yld
  38. 3 RUN:cpu
  39. 4 RUN:cpu
  40. 5 RUN:yld
  41. ```
  42. #### 例2
  43. ```
  44. $./process-simulation.py -l 5:50,5:50
  45. Produce a trace of what would happen when you run these processes:
  46. Process 0
  47. yld
  48. yld
  49. cpu
  50. cpu
  51. yld
  52. Process 1
  53. cpu
  54. yld
  55. cpu
  56. cpu
  57. yld
  58. Important behaviors:
  59. System will switch when the current process is FINISHED or ISSUES AN YIELD
  60. Time PID: 0 PID: 1
  61. 1 RUN:yld READY
  62. 2 READY RUN:cpu
  63. 3 READY RUN:yld
  64. 4 RUN:yld READY
  65. 5 READY RUN:cpu
  66. 6 READY RUN:cpu
  67. 7 READY RUN:yld
  68. 8 RUN:cpu READY
  69. 9 RUN:cpu READY
  70. 10 RUN:yld READY
  71. 11 RUNNING DONE
  72. ```