《操作系统》的实验代码。
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

1.8 KiB

设计一个简化的进程管理子系统,可以管理并调度如下简化进程.给出了参考代码

进程的状态

  • RUNNING - 进程正在使用CPU
  • READY - 进程可使用CPU
  • DONE - 进程结束

进程的行为

  • 使用CPU,
  • 发出YIELD请求,放弃使用CPU

进程调度

  • 使用FIFO/FCFS:先来先服务

关键模拟变量

  • 进程列表:描述了进程的行为特征:(1)使用CPU ;(2)等待I/O
   -l PROCESS_LIST, --processlist= X1:Y1,X2:Y2,...
   X 是进程的执行指令数; 
   Y是执行CPU的比例(0..100) ,如果是100,表示不会发出yield操作
  • 进程切换行为:系统决定何时(when)切换进程:进程结束或进程发出yield请求

进程执行

instruction_to_execute = self.proc_info[self.curr_proc][PROC_CODE].pop(0)

执行实例

例1

$./process-simulation.py -l 5:50
Process 0
  yld
  yld
  cpu
  cpu
  yld

Important behaviors:
  System will switch when the current process is FINISHED or ISSUES AN YIELD
Time     PID: 0 
  1     RUN:yld 
  2     RUN:yld 
  3     RUN:cpu 
  4     RUN:cpu 
  5     RUN:yld 

例2

$./process-simulation.py  -l 5:50,5:50
Produce a trace of what would happen when you run these processes:
Process 0
  yld
  yld
  cpu
  cpu
  yld

Process 1
  cpu
  yld
  cpu
  cpu
  yld

Important behaviors:
  System will switch when the current process is FINISHED or ISSUES AN YIELD
Time     PID: 0     PID: 1 
  1     RUN:yld      READY 
  2       READY    RUN:cpu 
  3       READY    RUN:yld 
  4     RUN:yld      READY 
  5       READY    RUN:cpu 
  6       READY    RUN:cpu 
  7       READY    RUN:yld 
  8     RUN:cpu      READY 
  9     RUN:cpu      READY 
 10     RUN:yld      READY 
 11     RUNNING       DONE