#lec10 进程/线程控制spoc练习
(1) (spoc)设计一个简化的进程管理子系统,可以管理并调度如下简化进程.给出了参考代码,请理解代码,并完成"YOUR CODE"部分的内容. 可2个人一组
- RUNNING - 进程正在使用CPU
- READY - 进程可使用CPU
- WAIT - 进程等待I/O完成
- DONE - 进程结束
- 使用CPU,
- 发出YIELD请求,放弃使用CPU
- 发出I/O操作请求,放弃使用CPU
PROC_CODE = 'code_'
PROC_PC = 'pc_'
PROC_ID = 'pid_'
PROC_STATE = 'proc_state_'
-l PROCESS_LIST, --processlist= X1:Y1,X2:Y2,...
X 是进程的执行指令数;
Y是执行yield指令(进程放弃CPU,进入READY状态)的比例(0..100)
Z是执行I/O请求指令(进程放弃CPU,进入WAIT状态)的比例(0..100)
instruction_to_execute = self.proc_info[self.curr_proc][PROC_CODE].pop(0)
$./process-simulation.py -l 5:30:30,5:40:30 -c
Produce a trace of what would happen when you run these processes:
Process 0
io
io
yld
cpu
yld
Process 1
yld
io
yld
yld
yld
Important behaviors:
System will switch when the current process is FINISHED or ISSUES AN YIELD or IO
Time PID: 0 PID: 1 CPU IOs
1 RUN:io READY 1
2 WAITING RUN:yld 1 1
3 WAITING RUN:io 1 1
4 WAITING WAITING 2
5 WAITING WAITING 2
6* RUN:io WAITING 1 1
7 WAITING WAITING 2
8* WAITING RUN:yld 1 1
9 WAITING RUN:yld 1 1
10 WAITING RUN:yld 1 1
11* RUN:yld DONE 1
12 RUN:cpu DONE 1
13 RUN:yld DONE 1