吉林大学操作系统PPT课件作业解析.ppt
《吉林大学操作系统PPT课件作业解析.ppt》由会员分享,可在线阅读,更多相关《吉林大学操作系统PPT课件作业解析.ppt(25页珍藏版)》请在三一办公上搜索。
1、操作系统作业(一),作业 #1,进程切换时需要保存哪些现场信息?请尽量考虑完全。,答案:进程切换过程是进程上下文的切换过程,进程上下文是指进程运行的物理环境。包括地址映寄存器、通用寄存器、浮点寄存器、SP、PSW(程序状态字)、PC(指令计数器)、以及打开文件表等。,2. 由核心返回目态程序时,进程的PSW和PC为何必须用一条机器指令同时恢复?,答案:中断向量中程序状态字PSW和指令计数器PC的内容必须由一条指令同时恢复,这样才能保证系统状态由管态转到目态的同时,控制转到上升进程的断点处继续执行。如果不同时恢复,则只能 1.先恢复PSW再恢复PC,在恢复PSW后已经转到目态,操作系统恢复PC的
2、使命无法完成 2.先恢复PC再恢复PSW,PC改变后转到操作系统另外区域(因为PSW仍在系统状态),PSW无法恢复,作业 #2,Consider the following program:var blocked: array0.1of boolean; turn:0.1;procedure P(id:integer);begin repeat blockedid:=true; while turnid do begin while blocked1-id do nothing turn:=id end; blockedid:=false; until falseend;,begin bloc
3、ked0:=false; blocked1:=false; turn:=0; parbegin P(0); P(1) parend;end.This is a software solution to the mutual exclusion problem proposed by Hyman. Find a counter example to demonstrate that this solution is incorrect. It is interesting to note that even the Communication of the ACM was fooled on t
4、his one.,begin repeat blockedid:=true; while turnid do begin while blocked1-id do nothing (1) turn:=id end; 若turn=1, blocked0:=true, blocked1:= false ,P(0), P(1)并发执行, P(0)先推进,当P(0)执行到while blocked1-id 时不满足条件跳出循环在(1)处让出处理机P(1)推进, P(1)执行while turnid 而进入临界区后让出处理机, P(0), 继续也进入临界区,不满足正确性。,作业 #3,关于读者写者问题改
5、进算法semaphore r_w_w ,mutex ,s=1;int count=0;写者活动:P(s);P(r_w_w);写操作;V(r_w_w);V(s);,读者活动:P(s);P(mutex);count+;if (count=1) p(r_w_w);V(mutex);V(s);读操作;P(mutex);count-;if (count=0) v(r_w_w);V(mutex);,写者优先算法int readcount ,writecount =0;semaphore rsem, wsem =1;Semaphore x ,y , z =1;,Reader: writer: p(z) 1
6、p(y) p(rsem) 2 writecount+ p(x) if(writecount=1)p(rsem) 4 readcount+ v(y) if(readcount=1) p(wsem) p(wsem) 5 v(x) v(rsem) 3 v(wsem) v(z) p(y) writecount- p(x) if(writecount=0) readcount- v(rsem) 6 if(readcount=0) v(wsem) 7 v(y) v(x),作业 #4,设系统有5台类型相同的打印机,依次编号为1-5。又设系统有n个使用打印机的进程,使用前申请,使用后释放。每个进程都有一个进程
7、标识,用于区分不同的进程。每个进程有一个优先数,不同进程的优先数各异。当有多个进程同时申请打印机时,按照进程优先数由高到低的次序实施分配。试用信号量和PV操作实现对打印机资源的管理,即要求编写如下函数和过程。,(1)函数require(pid,pri):申请一台打印机。参数pid为进程标识,其值为1-n之间的一个整数;pri为进程优先数,其值为正整数。函数返回值为所申请到的打印机的编号,其值为1-5的一个整数。(2)过程return(prnt):释放一台打印机。参数prnt为所释放的打印机的编号,其值为1-5的一个整数。,int lp5; (initial value is 1) int co
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 吉林大学 操作系统 PPT 课件 作业 解析
链接地址:https://www.31ppt.com/p-1406243.html