欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    2022年操作系统设备管理实验代码 .pdf

    • 资源ID:32429776       资源大小:93.98KB        全文页数:17页
    • 资源格式: PDF        下载积分:4.3金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要4.3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    2022年操作系统设备管理实验代码 .pdf

    #include using namespace std; / typedef struct node char name10; char devname10; struct node *next; PCB;/ 进程PCB * run;/执行队列/ typedef struct Node char identify10;/标识int state;/设备状态PCB *blocking;/阻塞队列指针CHCT;/ 通道控制表CHCT * CH1, * CH2; / typedef struct NOde char identify10;/标识int state;/设备状态CHCT * chct;/CHCT PCB *blocking;/阻塞队列指针struct NOde *next; COCT;/ 控制器控制表COCT * cohead; typedef struct NODe char identify10;/标识char type;/设备类型int state;/设备状态int times;/重复执行次数PCB *blocking;/阻塞队列指针COCT * coct;/COCT DCT;/ 设备控制表typedef struct NODE char type;/类别char identify10;/标识DCT * dct;/DCT / 驱动入口地址struct NODE *next; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 17 页 - - - - - - - - - SDT; / 系统设备表SDT * head; SDT * checkdel; void Init() PCB * ch1block,* ch2block,* co1block,* co2block,* co3block,* d1block,* d2block,* d3block,* d4block; COCT * CO1,* CO2,* CO3; DCT *d1,*d2,*d3,*d4; SDT *s1,*s2,*s3,*s4; /= run=(PCB *)malloc(sizeof(PCB); run-next=NULL; CH1=(CHCT *)malloc(sizeof(CHCT); CH2=(CHCT *)malloc(sizeof(CHCT); strcpy(CH1-identify,ch1); strcpy(CH2-identify,ch2); CH1-state=0; CH2-state=0; ch1block=(PCB *)malloc(sizeof(PCB); ch1block-next=NULL; ch2block=(PCB *)malloc(sizeof(PCB); ch2block-next=NULL; CH1-blocking=ch1block; CH2-blocking=ch2block; cohead=(COCT *)malloc(sizeof(COCT); cohead-next=NULL; CO1=(COCT *)malloc(sizeof(COCT); cohead-next=CO1; CO1-next=NULL; CO2=(COCT *)malloc(sizeof(COCT); CO1-next=CO2; CO2-next=NULL; CO3=(COCT *)malloc(sizeof(COCT); CO2-next=CO3; CO3-next=NULL; CO1-state=0; CO2-state=0; CO3-state=0; co1block=(PCB *)malloc(sizeof(PCB); co1block-next=NULL; co2block=(PCB *)malloc(sizeof(PCB); co2block-next=NULL; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 17 页 - - - - - - - - - co3block=(PCB *)malloc(sizeof(PCB); co3block-next=NULL; strcpy(CO1-identify,co1); strcpy(CO2-identify,co2); strcpy(CO3-identify,co3); CO1-chct=CH1; CO2-chct=CH1; CO3-chct=CH2; CO1-blocking=co1block; CO2-blocking=co2block; CO3-blocking=co3block; /= d1block=(PCB *)malloc(sizeof(PCB); d2block=(PCB *)malloc(sizeof(PCB); d3block=(PCB *)malloc(sizeof(PCB); d4block=(PCB *)malloc(sizeof(PCB); d1block-next=NULL; d2block-next=NULL; d3block-next=NULL; d4block-next=NULL; d1=(DCT *)malloc(sizeof(DCT); strcpy(d1-identify,P); d2=(DCT *)malloc(sizeof(DCT); strcpy(d2-identify,T); d3=(DCT *)malloc(sizeof(DCT); strcpy(d3-identify,K); d4=(DCT *)malloc(sizeof(DCT); strcpy(d4-identify,M); d1-coct=CO1; d2-coct=CO2; d3-coct=CO3; d4-coct=CO3; d1-state=0; d2-state=0; d3-state=0; d4-state=0; d1-type=o; d2-type=o; d3-type=i; d4-type=i; d1-blocking=d1block; d2-blocking=d2block; d3-blocking=d3block; d4-blocking=d4block; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 17 页 - - - - - - - - - /= head=(SDT *)malloc(sizeof(SDT); head-next=NULL; s1=(SDT *)malloc(sizeof(SDT); s2=(SDT *)malloc(sizeof(SDT); s3=(SDT *)malloc(sizeof(SDT); s4=(SDT *)malloc(sizeof(SDT); head-next=s1; s1-next=s2; s2-next=s3; s3-next=s4; s4-next=NULL; s1-dct=d1; s2-dct=d2; s3-dct=d3; s4-dct=d4; strcpy(s1-identify,P); strcpy(s2-identify,T); strcpy(s3-identify,K); strcpy(s4-identify,M); s1-type=o; s2-type=o; s3-type=i; s4-type=i; /test SDT *temp=head-next; /= / 添加设备时候,添加新控制器,把控制器加到最后void Addcotrol (COCT *temp) COCT *cotemp=cohead; while(cotemp-next!=NULL) cotemp=cotemp-next; cotemp-next=temp; temp-next=NULL; / 查看所有控制器,选择所要连接的控制器void Showallco() COCT *temp=cohead-next; while(temp!=NULL) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 17 页 - - - - - - - - - coutidentifynext; coutnext; while(temp!=NULL) if(!strcmp(temp-identify,a) return temp; temp=temp-next; return temp; / 删除设备时候,判断是不是同时删除控制器, 等于 1 删, 0 不删int sf_deleteco(char a,char b) SDT *temp; temp=head-next; while(temp!=NULL) if(strcmp(temp-identify,a)&(!strcmp(temp-dct-coct-identify,b) return 0; temp=temp-next; return 1; / 删除设备的时候同时删除控制器void Deletecotrol(COCT *te) COCT * temp=cohead; while(temp-next!=te) temp=temp-next; temp-next=te-next; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 17 页 - - - - - - - - - delete(te); / 添加设备,查找设备是不是已经存在int sf_exist(char a) SDT *temp; if(head-next=NULL) return 0; else temp=head-next; while(temp!=NULL) if(!strcmp(a,temp-identify) checkdel=temp; return 1; temp=temp-next; return 0; / 申请设备时候,如果忙,将设备挂到等待队列void Addwaitpcb(PCB * p1,PCB * p2) PCB *temp=p1; while(temp-next!=NULL) temp=temp-next; temp-next=p2; p2-next=NULL; / 回收设备时候,对PCB的操作void Deletepcb(char a) PCB * temp2=run-next,* temp=run; while(temp2!=NULL) if(!strcmp(temp2-devname,a) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 17 页 - - - - - - - - - temp-next=temp2-next; delete(temp2); break; temp=temp2; temp2=temp-next; / 判断等待队列是不是空int sf_pcbnull(PCB *temp) if(temp-next=NULL) return 0; else return 1; / 查看所有设备状态void Showmenu() PCB * ptemp=run-next; SDT * temp=head-next; DCT * dtemp; COCT * cotemp; CHCT * chtemp; coutSDT i/o COCT CHCTdct; cotemp=dtemp-coct; chtemp=cotemp-chct; coutidentifystatettypetidentifystate tidentifystatenext; while(ptemp!=NULL) cout 进程 name 申请了设备 devnamenext; coutnext=NULL) return 0; else temp=head-next; while(temp!=NULL) if(temp-type=ch) return 1; else temp=temp-next; return 0; / 增加设备void Adddevice() cout 增加设备 eqary; / 此处查找SDT ,看是否所要添加的设备已经存在if(sf_exist(eqary)=1) /设备已经存在cout 设备已存在 next=NULL; temp=(DCT *)malloc(sizeof(DCT); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 17 页 - - - - - - - - - strcpy(temp-identify,eqary); temp-blocking=tempblock; temp-state=0; cout 输入设备类型temptype; temp-type=temptype; stemp=(SDT *)malloc(sizeof(SDT); stemp-next=NULL; stemp-dct=temp; stemp-type=temptype; strcpy(stemp-identify,eqary); s2temp=head; while(s2temp-next!=NULL) s2temp=s2temp-next; s2temp-next=stemp; stemp-next=NULL; cout 是否添加控制器?(y/n)choice; if(choice=y)|(choice=Y) / 添加新控制器cout 输入控制器名称:coary; cotempblock=(PCB *)malloc(sizeof(PCB); cotempblock-next=NULL; cotemp=(COCT *)malloc(sizeof(COCT); cotemp-next=NULL; strcpy(cotemp-identify,coary); cotemp-state=0; cotemp-blocking=cotempblock; Addcotrol(cotemp); temp-coct=cotemp; cout 请选择连接的通道:1/2i; if(i=1) cotemp-chct=CH1; else cotemp-chct=CH2; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 17 页 - - - - - - - - - else / 不添加控制器Showallco(); cout 输入连接控制器的名称:coary; cotemp=Findco(coary); temp-coct=cotemp; cout 设备 eqary 添加成功 !endl; / 删除设备void Deletedevice() /删除设备的时候同时删除pcb Deletepcb cout 删除设备 chary; if(sf_exist(chary)=0) cout 删除设备不存在!dct-state=1) cout 设备正在使用无法删除dct-coct-identify); if(sf_deleteco(chary,tempary) / 删除控制器temp=checkdel-dct-coct; Deletecotrol(temp); stemp=head; while(stemp-next!=checkdel) stemp=stemp-next; stemp-next=checkdel-next; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 17 页 - - - - - - - - - delete(checkdel); cout 设备 chary 删除成功 !endl; / 申请设备void Applydevice() cout 申请设备 pnameeqname; if(sf_exist(eqname)=0) cout 设备不存在 !name,pname); ptemp-next=NULL; dtemp=checkdel-dct; /=此处是否要考虑状态的改变= if(dtemp-state=1) / 设备忙Addwaitpcb(dtemp-blocking,ptemp); cout 进程 name 被挂在设备identify的等待队列上 !coct; if(cotemp-state=1) /控制器忙Addwaitpcb(cotemp-blocking,ptemp); cout 进程 name 被挂在控制器 identify的等待队列上 !chct; if(chtemp-state=1) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 17 页 - - - - - - - - - /通道忙Addwaitpcb(chtemp-blocking,ptemp); cout 进程 name 被挂在通道 identify的等待队列上!state=1; cotemp-state=1; chtemp-state=1; strcpy(ptemp-devname,eqname); cout 进程 pname申请设备 eqname成功 !endl; / 回收设备void Recycledevice() cout 回收设备 eqname; if(sf_exist(eqname)=0) /设备不存在cout 要回收的设备不存在!dct-state=0) /设备存在,但是不需要回收cout 设备处于闲状态,不需要回收!dct; cotemp=dtemp-coct; chtemp=cotemp-chct; dtemp-state=0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 17 页 - - - - - - - - - cotemp-state=0; chtemp-state=0; if(sf_pcbnull(chtemp-blocking) / 如果通道等待队列不空pctemp1=chtemp-blocking; pctemp2=pctemp1-next; pctemp1-next=pctemp2-next; pctemp2-next=NULL; strcpy(pctemp2-devname,eqname); Addwaitpcb(run,pctemp2); dtemp-state=1; cotemp-state=1; chtemp-state=1; else if(sf_pcbnull(cotemp-blocking) /如果控制器的等待队列不空pctemp1=cotemp-blocking; pctemp2=pctemp1-next; pctemp1-next=pctemp2-next; pctemp2-next=NULL; strcpy(pctemp2-devname,eqname); Addwaitpcb(run,pctemp2); dtemp-state=1; cotemp-state=1; chtemp-state=1; else if(sf_pcbnull(dtemp-blocking) /如果设备的等待队列不空pctemp1=dtemp-blocking; pctemp2=pctemp1-next; pctemp1-next=pctemp2-next; pctemp2-next=NULL; strcpy(pctemp2-devname,eqname); Addwaitpcb(run,pctemp2); dtemp-state=1; cotemp-state=1; chtemp-state=1; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 17 页 - - - - - - - - - cout 设备 eqname回收成功 !endl; / 设备独立性 = void Independence() cout 设备独立性 - 申请设备 :endl; /cout申请设备 pnametype; if(type=o)|(type=i) /= 还得考虑要申请的类型是不是存在= if(sf_typeexist(type)=0) cout 要申请的该类设备不存在!next; while(temp!=NULL) if(temp-type=type)&(temp-dct-state=0) /当设备类型相同,并且设备空闲temp2=temp; break; else if(temp-type=type) temp2=temp; temp=temp-next; sf_exist(temp2-identify);/= ptemp=(PCB *)malloc(sizeof(PCB); strcpy(ptemp-name,pname); ptemp-next=NULL; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 17 页 - - - - - - - - - dtemp=checkdel-dct;/要用了这个函数才可以= if(temp2-dct-state=0) /当设备不忙时候cotemp=dtemp-coct; if(cotemp-state=1) /控制器忙Addwaitpcb(cotemp-blocking,ptemp); cout进程name被挂在控制器identify的等待队列上!chct; if(chtemp-state=1) /通道忙Addwaitpcb(chtemp-blocking,ptemp); cout进程name被挂在通道identify的等待队列上!state=1; cotemp-state=1; chtemp-state=1; strcpy(ptemp-devname,temp2-identify); cout 进 程 pname 申 请 设 备 identify成功!blocking,ptemp); cout 进程 name 被挂在设备identify的等待队列上 !endl; else cout 输入设备的类型错误!endl; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 15 页,共 17 页 - - - - - - - - - / void Show() coutA :增加设备 endl; coutD :删除设备 endl; coutS :申请设备 endl; coutH :回收设备 endl; coutI :设备独立性 endl; coutQ :退出 endl; / int main() cout 操作系统实验三 endl; cout endl; cout相关指令: endl; Init(); Show(); char choice; while(true) Showmenu(); cout 选择指令 :choice; switch(choice) case a: case A: Adddevice(); break; case d: case D: Deletedevice(); break; case s: case S: Applydevice(); break; case h: case H: Recycledevice(); break; case q: case Q: 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 16 页,共 17 页 - - - - - - - - - exit(0); case i: case I: Independence(); break; default : cout 指令错误 endl; break; return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 17 页,共 17 页 - - - - - - - - -

    注意事项

    本文(2022年操作系统设备管理实验代码 .pdf)为本站会员(H****o)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开