ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:100.39KB ,
资源ID:8875159      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8875159.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(实验5设备管理.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

实验5设备管理.docx

1、实验5设备管理实验5:设备管理要求:编写程序实现对独占设备的分配与回收的模拟,该程序中包括:建立设备类表和设备表、分配设备和回收设备的函数。提示:1、 设备类表和设备控制表的内容可以设计成如下形式:设备类表设备类拥有设备数量可分配设备数量设备表起始地址Input522Printer435设备控制表绝对号设备状态是否分配占有作业名相对号11好/坏是/否Job12、 作业申请某设备时,先查“设备类表”,如果该类设备的可分配设备数量满足申请要求,则从设备类表中得到该类设备的设备表起始地址,然后找到“设备控制表”中该类设备的起始地址,一次查询该类设备的表项,找到设备状态是“好”且没有被分配的设备分配给

2、作业。分配时需要修改“设备类表”中可分配设备数量,并且把“设备控制表”中设备“是否分配”项更改为“是”,并填写占有作业名和相对号。3、 设备回收时,系统首先查看“设备控制表”,找到需要释放的设备,将该设备“是否分配”项更改为“否”,然后在“设备类表”中将“可分配设备数量”加1。源程序代码:#include iostream#include string#include vectorusing namespace std;typedef struct node string ID; /进程名 string equipment; /申请的设备名 struct node *next; PCB;typ

3、edef struct string channelID; /通道标识符 bool state; /通道状态 PCB *use; /正在使用该通道的进程 PCB *blockqueue; /阻塞队首CHCT;typedef struct string controllerID; /控制器标示 bool state; /控制器状态 CHCT *front; /通道表指针 PCB *use; /正在使用该控制器的进程 PCB *blockqueue; /阻塞队首COCT;typedef struct char type; /设备类型 string equipmentID; /设备名 bool st

4、ate; /设备状态 COCT *front; /控制器指针 PCB *use; /正在使用该设备的进程 PCB *blockqueue; /阻塞队首DCT;typedef struct char type; /设备类型 string equipmentID; /设备名 DCT *dct; /设备的DCTSDT;DCT *k=new DCT; /键盘的DCTDCT *m=new DCT;DCT *p=new DCT;DCT *t=new DCT;COCT *c1=new COCT;COCT *c2=new COCT;COCT *c3=new COCT;CHCT *h1=new CHCT;CHC

5、T *h2=new CHCT;CHCT *h3=new CHCT;int check(char cmd) switch(cmd) case c: /申请 return 1; case C: return 1; case d: /删除 return 2; case D: return 2; case a: /添加 return 3; case A: return 3; case f: /释放 return 4; case F: return 4; case q: return -1; case Q: return -1; case p: return 5; case P: return 5; d

6、efault: return 0; void init(vector &SDT_table) SDT_table0.equipmentID=M; SDT_table0.type=2; /鼠标是第二类设备 SDT_table0.dct=m; /设备的DCT表位置 SDT_table1.equipmentID=K; SDT_table1.type=1; SDT_table1.dct=k; SDT_table2.equipmentID=P; SDT_table2.type=3; SDT_table2.dct=p; SDT_table3.equipmentID=T; SDT_table3.type=4

7、; SDT_table3.dct=t; h1-blockqueue=NULL; h1-channelID=通道1; h1-state=true; h1-use=NULL; h2-blockqueue=NULL; h2-channelID=通道2; h2-state=true; h2-use=NULL; c1-blockqueue=NULL; c1-controllerID=控制器1; c1-state=true; c1-front=h1; c1-use=NULL; c2-blockqueue=NULL; c2-controllerID=控制器2; c2-state=true; c2-front

8、=h1; c2-use=NULL; c3-blockqueue=NULL; c3-controllerID=控制器3; c3-state=true; c3-front=h2; c3-use=NULL; k-blockqueue=NULL; k-equipmentID=K; k-state=true; /可用 k-type=1; k-front=c1; k-use=NULL; m-blockqueue=NULL; m-equipmentID=M; m-state=true; m-type=2; m-front=c1; m-use=NULL; p-blockqueue=NULL; p-equipm

9、entID=P; p-state=true; p-type=3; p-front=c2; p-use=NULL; t-blockqueue=NULL; t-equipmentID=T; t-state=true; t-type=4; t-front=c3; t-use=NULL;int main() char cmd; DCT *temp_dct; COCT *temp_coct; CHCT *temp_chct; int l=0; string ID; string name; vector SDT_table(4); /设备表 vector DCT_table(4); /设备 vector

10、 COCT_table(3); /控制器表/ vector:size_type size_SDT_table; /设备表长度 init(SDT_table); /设备表的初始化 DCT u=*k; DCT_table.push_back(u); u=*m; DCT_table.push_back(u); u=*p; DCT_table.push_back(u); u=*t; DCT_table.push_back(u); COCT cu=*c1; COCT_table.push_back(cu); cu=*c2; COCT_table.push_back(cu); cu=*c3; COCT_t

11、able.push_back(cu); cout目前已有设备(数量):K:键盘(1) M:鼠标(2) P:打印机(3) T:显示器(4)endl; coutendl; cout选择 c 申请使用设备。endl; cout选择 d 删除设备。endl; cout选择 f 释放设备。endl; cout选择 a 添加设备。endl; while(l!=-1) coutendl; cout ; cincmd; l=check(cmd); if(l=0) cout指令错误重新输入。endl; continue; else if(l=1) /申请使用设备 cout想要使用的设备名:ID; cout申请设

12、备的进程名:name; PCB *head=new PCB; /申请PCB的创建和链接 head-equipment=name; head-ID=ID; head-next=NULL; bool find=false; vector:iterator ator0; for(ator0=SDT_table.begin();ator0!=SDT_table.end();ator0+) if(ator0-equipmentID=ID) find=true; /有该设备 break; if(!find) cout没有该设备。dct; if(!temp_dct-state) /设备忙 cout该设备目前

13、处于忙状态,已经把请求加入等待队列。blockqueue) /阻塞的队列为空 temp_dct-blockqueue=head; else /阻塞队列已经有内容 PCB* t=temp_dct-blockqueue; while(t) t=t-next; if(!t) temp_dct-blockqueue=NULL; else t-next=head; else /设备空闲 temp_coct=temp_dct-front; temp_dct-state=false; temp_dct-use=head; /添加正在占用设备的进程 if(!temp_coct-state) /控制器不可用 c

14、out目前该设备连接的控制器忙,已经把请求加入等待队列。blockqueue) /阻塞的队列为空 temp_coct-blockqueue=head; else /阻塞队列不空 PCB* t=temp_coct-blockqueue; while(t) t=t-next; if(!t) temp_dct-blockqueue=NULL; else t-next=head; else /控制器可用 temp_coct-state=false; /控制器置忙 temp_chct=temp_coct-front; temp_coct-use=head; if(!temp_chct-state) /通

15、道不可用 cout目前该设备连接的通道忙,已经把请求加入等待队列。blockqueue) /阻塞队列为空 temp_chct-blockqueue=head; else /阻塞队列不为空 PCB* t=temp_coct-blockqueue; while(t) t=t-next; if(!t) temp_dct-blockqueue=NULL; else t-next=head; else /通道可用 temp_chct-use=head; temp_chct-state=false; /通道状态置忙 cout该设备已经成功申请。endl; else if(l=2) /删除设备 vector

16、:iterator ator; vector:iterator ator1; cout现在系统拥有的设备如下:endl; for(ator=SDT_table.begin();ator!=SDT_table.end();ator+) coutequipmentID ; coutname; for(ator=SDT_table.begin();ator!=SDT_table.end();ator+) if(ator-equipmentID=name) /查找到了该设备 ator1=ator-dct; COCT *temp=ator1-front; ator-dct=NULL; SDT_table

17、.erase(ator); /从设备表中删除 ator=SDT_table.begin();/* for(ator=SDT_table.begin();ator!=SDT_table.end();ator+) coutequipmentID ; coutuse) if(temp-use-equipment=name) /该设备正在占用控制器 if(!temp-blockqueue) /控制器的等待队列为空 temp-state=true; temp-use=NULL; else /控制器的等待队列有内容 PCB *tt=temp-blockqueue; temp-blockqueue-next

18、=tt-next; temp-use=tt; tt-next=NULL; else /该设备没有占用控制器 temp-blockqueue=NULL; ator1-blockqueue=NULL; ator1-front=NULL; ator1-use=NULL; vector:iterator ator2; vector D; for(ator2=DCT_table.begin();ator2!=DCT_table.end();ator2+) if(ator2!=ator1) D.push_back(*ator2); DCT_table=D;/ ator1=DCT_table.erase(a

19、tor1); /删除该设备 break; if(ator=SDT_table.end() /判断是否查找到设备 cout没有该设备。endl; else cout成功删除该设备。endl; else if(l=3) /添加设备 SDT SDT_add; DCT DCT_add; int select; coutDCT_add.equipmentID; SDT_add.equipmentID=DCT_add.equipmentID; coutDCT_add.type; SDT_add.type=DCT_add.type; SDT_add.dct=&DCT_add; DCT_add.blockqu

20、eue=NULL; DCT_add.use=NULL; DCT_add.state=true; SDT_table.push_back(SDT_add); DCT_table.push_back(DCT_add); cout是否需要新增控制器: 1.新增。 2.利用以前的。select; if(select=1) /新增 COCT c; c.blockqueue=NULL; c.state=true; coutc.controllerID; c.use=NULL; DCT_add.front=&c; cout1.channelIDt 2.channelIDendl; coutselect; i

21、f(select=1) /链接到两个不同的通道 c.front=h1; else c.front=h2; cout连接成功。endl; COCT_table.push_back(c); else /利用以前的控制器 for(vector:iterator ator=COCT_table.begin();ator!=COCT_table.end();ator+) /输出现有控制器名称 coutcontrollerIDendl; coutname; for(ator=COCT_table.begin();ator!=COCT_table.end();ator+) /按名字进行选择 if(ator-

22、controllerID=name) DCT_add.front=ator; cout链接成功。endl; break; else if(l=4) /释放设备资源 coutname; DCT *DCT_temp; /暂存DCT COCT *COCT_temp; /暂存COCT CHCT *CHCT_temp; /暂存CHCT for(vector:size_type i=0;ifront; CHCT_temp=COCT_temp-front; if(!DCT_temp-use) /如果该设备没有被使用 cout该设备未被占用,无需释放。use-ID=name) /该设备目前占用通道时 if(!

23、CHCT_temp-blockqueue) /通道的等待队列无内容 CHCT_temp-state=true; CHCT_temp-use=NULL; else /通道的等待队列不为空 CHCT_temp-use=CHCT_temp-blockqueue; CHCT_temp-blockqueue=CHCT_temp-blockqueue-next; if(COCT_temp-use-ID=name) /设备占用控制器 if(!COCT_temp-blockqueue) /控制器的等待队列为空 COCT_temp-use=NULL; COCT_temp-state=true; else /控制

24、器等待队列有内容 COCT_temp-use=COCT_temp-blockqueue; COCT_temp-blockqueue=COCT_temp-blockqueue-next; if(!DCT_temp-blockqueue) /设备自身的等待队列 /为空 DCT_temp-state=true; DCT_temp-use=NULL; break; else /该设备目前被其他进程申请(队列不空) DCT_temp-use=DCT_temp-blockqueue; DCT_temp-blockqueue=DCT_temp-blockqueue-next; break; if(!COCT_temp-use) COCT_temp-use=DCT_temp-use; COCT_temp-state=false; if(!CHCT_temp-use) CHCT_temp-use=COCT_temp-use; CHCT_temp-state=false; if(i=SDT_table.size() cout该设备不存在。endl; else cout成功释放该设备。endl; return 0;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1