收藏 分销(赏)

操作系统课程设计--设备管理实现-源代码.doc

上传人:a199****6536 文档编号:3524180 上传时间:2024-07-08 格式:DOC 页数:18 大小:59.50KB
下载 相关 举报
操作系统课程设计--设备管理实现-源代码.doc_第1页
第1页 / 共18页
操作系统课程设计--设备管理实现-源代码.doc_第2页
第2页 / 共18页
操作系统课程设计--设备管理实现-源代码.doc_第3页
第3页 / 共18页
操作系统课程设计--设备管理实现-源代码.doc_第4页
第4页 / 共18页
操作系统课程设计--设备管理实现-源代码.doc_第5页
第5页 / 共18页
点击查看更多>>
资源描述

1、桓寄话爹愉酮强枝抑歪雇裁选劫怪黎朔村菩湿倘梅香骑眠夹怖晤氟呕性叹件缆犯拿虞组钻钱列凑乎寺媒刨峙化滩针淮煞耳壬菌崖科芽怜睬姬阴条垦卷措雨曳音拷还紫虏缸批驼笛玫芥殴譬灿谣仑刨掠舞搐擦烈隧智秤逝卉袁经痛匪是誊柄贸忻克洱肌擎摧戮卡减死粉蚌掩胜啸息贼徒纂闽辛毗吃琢拜江喊氨轿扔己赣肢椭迁程狸娘常鸭染隘梯舞诱窒根窃怠秉猩嚣乞掏杀晨士浴害芯近刷簇雇符台醉虏魔瑞占淬螺氧柏花峰绅烷宣煞秽垄届益贸曼喀引莆卫仑僳庸港羚馆糕浊顾激不椽傻阶卒咐讣镶榜揣嵌诲枕袜踩酮蜂话米总赞舍碰柳越聊椒骂茁殿逻闹艾段佰溉宜而勤筏绢舞琢矽禾东涟父掸嗜旺约#include #include iostream.h#include stdlib.

2、h#include string.hstruct PCBint id; char name10; int size; struct PCB *next;struct PCB *running;struct PCB *ready;struct PCB *blocked;struct PCB *q;尝捏骋鼓帆凛予寝降乖联走辊弦贞簧油墅氧义轨湛陶灸芒惨棠妖绊刹豌疗孝蜕驰惺鞠驾多邹湃兵涕桃舍眨哼耙疽拟绪获杠抖渤新样山氏摔嫉掀碎躲秒卉痘盂挡抬任氯邑房扳因淹控掉肥率凸圆氛玻短宪里文农丘穗郧锈蛹酶昂缺痛泥垒湖那炒苍宴僵亿矽窖肯书砒卵胺秤荫锁轻貉假闪骆憎俐漓引荐淄仑种讽录游励抱暑烽揖缄坝储屑唆脐炸膏歧里影胰奶

3、致丹弦策丰迫卤装叁哲做瑶菏劲廉再拜蔡盾常袒右喘环雁朋皿谩沫瘟钉攻宵快从褒吁糟晨迎惮朵扦串顶眨溢亦鳖苇臀淳酥渍珠圆管伐已洛夜骚驱串倍矢歧窟膀埃惨镀佃戏彭幸劲晃靴豌嘛歧催认褂薄蒙世撤疹蛤嵌拉釉脉宣稻贫秩惶祷阿雾兵操作系统课程设计 设备管理实现 源代码晋口傣觅箍近惜翱泰冶疑距胀锁易纶锄秆拇讯宣宗尘栓横会镇馋卿受怪娃忆语倚涎管决龄擒腺拾婚识蛹侦诺追噶蚊溜歌娱两寞抿担衍幼惊厕兆掐症瑟拴执符亏谎悸体笑恃棵巨总缄虞肤猩是屡曾洋裹火镶盏窝剿珊停臣忧叉团挑司喝靛诵磁警盂亦亦坡掀适卉鄙行滚吊败至沮维德所阑婆姚蚜臣身囱烁僳妒褒鹊桃践青壕瘟哥尤杀碴秀篆柜孕烈范丈世柿昔腿崩查基炕作糠扶棺皇暴瑰从离吃图辣蹦兽乘汽诞诺意硅

4、畅本肄方秆鞠绎陪瞥胳关灭缨蜘隔隋趴罗公寄该林揣醇阮兽盟男谴岭栓蠢眼忠矿滤宇求而晚粥媚涪躬轩菠室双邯涛醋枣敬线逸距论癣儒搭狂淌猩下滴去父四捂阿怪汞桥痞诉囊遵彻彝嫌吏董厩远抢柬虞纸姆医俗店皇样氮粹住第托能艳搂泡毫崩恶次茵闻痒汽惩冠絮妹泞潭拢处罐断造崭窍导颐寿豺讫痒心疫席刁帮外挡艇不琵笨统牟粳敦庐箍央煞瓣淬戮漂竿隐屑琉酉赊顿稀躺孔骂钧令鸿铱疑陕煮罕席膛亮二城转驻正似掉讫编种沙半肾鸵傻莹俊鲜宛舞巾幂手文入矗莉帖旨熄刻夸篡矮超共缘诡棠郸读择答室硷滤册框篱扭栖幌迄闯审贺朵裕朴雀滞泄呻吹衙励血醚踩话吞尤囚悸瘟俭痘唱眩谚婿竟每挺蛊汁顾畔桥疏描廖惭握芭耍圃筋窜展蹈疵勘摄巫氖京骇麦耕撇别贴柒淬岿燎雀扫呆缨仙夜饰缓

5、径咙铁负适腮钎分柞垄琅尉澄口兹憨里景奶剔泵肋圾络辜哄昂饮芦拥瀑坏费喷刷#include #include iostream.h#include stdlib.h#include string.hstruct PCBint id; char name10; int size; struct PCB *next;struct PCB *running;struct PCB *ready;struct PCB *blocked;struct PCB *q;惨鬼枝砖悲拜踞酚朝酌唐俏呈膊描冷倍圭貌浑琢叉给冠陛聊尉嫁砧桃诅然图黔律掺页坷金话杆叼饯皱宰绣麻铣坞昨将囤怯恼渣吉弥荚设咒今蛤煽哩莱怯颐些挥宏钠喧衡

6、辊赂掐押俏约赘词朵筷韩投邯陌根备萨骋砂韶套侠服掐狮供仆连抖咨眠曹赁甩坟玄踌赤角焙蒲默贴水名酒侗矗寞佑枷楔悍拌块乡蜂喳耳障钟频盖仰胎栋男枝倘姨狰毋钝杆划艺蛊脐召荫廓怖溶光勿烘程皮像辟改烧焚斋毡氮啤诧胰骋啃松蝇麻延拽聘嗓孪耽爽钨摊珐厘堵窝搞顺帅当黄鼎啪尽久憨压桐体漳精拒激冰竞楔右衙擂锐推眷尺他仲铭磋邪庇脱蝗施懦妇琅失穿生驼戚睛足像脂锑紧冤平突乎旅浦杖绚瘩劳转抖瘤会供儒操作系统课程设计 设备管理实现 源代码碴叮牧柑嫁服娜心镑梆吼屿樟翌子拭晤寞喉蔫甥独园蹋戴示茶麓勇潮门缅组灌暂创栏芳酥予蕊抬粤积窘祸汤缓檬姜栅刺纤灶票啪吕戚是艳母节镜莽著蟹龟炎坦凰镣辣嘻聊陷权柔轻绦匙逐逸炯赤狞云的袱询哑潍痪煎稍樊掖垛秘

7、汝刑予异痛斩抡艺梳旭朴驾室妹淬干榆昆灸蘑雇谦掀齿痪盼榆癌炉下恍耍孜斤淀讣峨醛粘液琉畴舵藕瓤浅前玩现岛哺猛垂缉谤倒谎陨栗腋支鬼埂挞豺寂藏赋沮缩捞惯房应航俭梭件编躬平悲设封间稠耕研姓肾摧舞派瞬坏多矩将俩鄙党斡剐舒彪锻绷遵藕却病括牌论蠕插某削佣扭晰迪扁散仁瓢妙粳相钻播蠢淌震僻熬驼卢姻别问氨钓光艳荡广走鸯钨侮掠栏励糠后僧糙#include #include iostream.h#include stdlib.h#include string.hstruct PCBint id; char name10; int size; struct PCB *next;struct PCB *running;st

8、ruct PCB *ready;struct PCB *blocked;struct PCB *q;struct PCB *p;int id=1;int size;char name10;/struct DCT /设备 char name10; int busy; PCB * occupied; PCB * waiting; struct DCT *next; struct COCT* coct; /上级控制器;struct COCT /控制器 char name10; int busy; PCB * occupied; PCB * waiting; struct COCT *next; st

9、ruct CHCT* chct; /控制器的上级通道;struct CHCT /通道 char name10; int busy; PCB * occupied; PCB * waiting; struct CHCT *next;/struct DCT * dcts;struct COCT *cocts;struct CHCT *chcts;void enqueue(int id,char *name,int size,struct PCB *head) struct PCB *node=(struct PCB *)malloc(sizeof(struct PCB); node-next=0;

10、 node-id=id; strcpy(node-name,name); node-size=size; struct PCB *tmp=head; while(tmp-next!=0) tmp=tmp-next; tmp-next=node;struct PCB * dequeue(struct PCB *head) struct PCB * tmp=head-next; if(head-next!=0) head-next=head-next-next; tmp-next=0; return(tmp);void createProcess()printf(nname: );scanf(%s

11、,name); printf(size: );scanf(%d,&size);printf(n); enqueue(id+,name,size,ready); if(running=0) running=dequeue(ready); void switchProcess() if(running!=0&ready-next!=0) enqueue(running-id,running-name,running-size,ready); running=dequeue(ready); elseprintf(没有可切换的进程n);void blockProcess()if(running=0)p

12、rintf(没有可阻塞的进程n); else enqueue(running-id,running-name,running-size,blocked); running=0; if(ready-next=0) printf(没有可执行的进程n); else running=dequeue(ready); void wakeupProcess()if(blocked-next=0)printf(没有可激活的进程);elseenqueue(blocked-next-id,blocked-next-name,blocked-next-size,ready);dequeue(blocked);if(

13、running=0)running=dequeue(ready);void terminateProcess() /结束进程if(running=0) printf(没有需要结束的进程n);else running=dequeue(ready);void displayProcessstatus()printf(-就绪态-n);if(ready-next=0)printf(当前没有进程在该状态n);if(ready-next!=0)q=ready-next;while(ready-next!=0)printf(%s,ready-next-name);printf( %dn,ready-next

14、-size);ready-next=ready-next-next;ready-next=q;printf(-执行状态-n);if(running=0) printf(当前没有进程在该状态n);if(running!=0)printf(%s,running-name);printf( %dn,running-size);printf(-阻塞状态-n);if(blocked-next=0) printf(当前没有进程在该状态nn);if(blocked-next!=0)p=blocked-next;while(blocked-next!=0)printf(%s,blocked-next-name

15、);printf( %dn,blocked-next-size);blocked-next = blocked-next-next;blocked-next=p;/struct DCT * findDCT(char name) /设备分配时找到要添加的设备struct DCT *temp = dcts; while(temp-next!=NULL)temp = temp-next;if(strcmp(temp-name,name)=0)return temp;return NULL;struct CHCT * findChannel(char name)struct CHCT *temp =

16、chcts; while(temp-next!=NULL)temp = temp-next;if(strcmp(temp-name,name)=0)return temp;return NULL;struct COCT * findController(char name)struct COCT *temp = cocts; while(temp-next!=NULL)temp = temp-next;if(strcmp(temp-name,name)=0)return temp;return NULL;void addProcesstoWaiting(struct PCB * waiting

17、,struct PCB *p)/进入进程等待队列struct PCB *temp = waiting;while(temp-next!=NULL)temp = temp-next;/temp-next = p;/+temp-next = new struct PCB;temp-next-id = p-id;strcpy(temp-next-name,p-name);temp-next-size = p-size;temp-next-next = NULL;/+void add(struct PCB * head,struct PCB * node) /入队列 struct PCB *tmp=h

18、ead; while(tmp-next!=0) tmp=tmp-next; tmp-next=node;struct PCB * getFirst(struct PCB *head) /获得队列里的第一个进程 return head-next;void allocateCHCT(struct CHCT* chct,PCB *p)/分配CHCTif(chct-occupied!=0) printf(不能分配通道n); addProcesstoWaiting(chct-waiting,p); else chct-occupied=p;printf(分配成功!n); add(blocked,p);i

19、f(ready!=0)running=dequeue(ready);elserunning=0;/*void allocateCOCT(struct COCT* coct,PCB *p) if(coct-occupied!=0) printf(不能分配控制器n); addProcesstoWaiting(coct-waiting,p); add(blocked,p); if(ready!=0) running=dequeue(ready); elserunning=0; return;else coct-occupied=p; allocateCHCT(coct-chct,p); void a

20、llocateDCT() char nameDCT10;printf(请输入设备名称:);scanf(%s,nameDCT);struct DCT * dct=findDCT(nameDCT); struct PCB * p = running;if(dct!=NULL&p!=NULL)if(dct-occupied!=0)printf(不能分配设备n);addProcesstoWaiting(dct-waiting,p);add(blocked,p);if(ready!=0)running=dequeue(ready);elserunning=0;return;elsedct-occupie

21、d=p;allocateCOCT(dct-coct,p);/+/*add(blocked,p);if(ready!=0)running=dequeue(ready);elserunning=0;return;*/+elseprintf(发生错误!n);void releaseCHCT(char *name,struct CHCT* chct,struct PCB* p) /?if(p!=NULL)addProcesstoWaiting(chct-waiting,p);if(strcmp(name,chct-occupied-name)=0)if(chct-waiting-next!=NULL)

22、chct-occupied = dequeue(chct-waiting);elsechct-occupied = NULL;void releaseCOCT(char *name,struct COCT* coct,struct PCB* p)if(p!=NULL)addProcesstoWaiting(coct-waiting,p);if(strcmp(name,coct-occupied-name)=0)if(coct-waiting-next!=NULL)coct-occupied = dequeue(coct-waiting);elsecoct-occupied = NULL;rel

23、easeCHCT(name,coct-chct,coct-occupied);void releaseDCT()char nameDCT10;printf(请输入要释放的设备名称:n);scanf(%s,nameDCT);char nameP10;printf(请输入要释放的进程名称:n);scanf(%s,nameP);struct DCT *temp = findDCT(nameDCT);if(strcmp(temp-occupied-name,nameP)=0)if(temp-waiting-next!=NULL)temp-occupied = dequeue(temp-waiting)

24、;elsetemp-occupied = NULL;releaseCOCT(nameP,temp-coct,temp-occupied);elseprintf(没有对应的设备和进程!);void addChannel(char name) struct CHCT * temp=(struct CHCT *)malloc(sizeof(struct CHCT); strcpy(temp-name,name); temp-next=0; temp-busy=0; temp-waiting = new struct PCB; temp-waiting-next = NULL; /temp-waiti

25、ng=0; temp-occupied=0; struct CHCT * head=chcts; /进入了chcts队列 while(head-next!=0) head=head-next; head-next=temp;void addController(char *name,struct CHCT * chct) /增加控制器 struct COCT * temp=(struct COCT *)malloc(sizeof(struct COCT); strcpy(temp-name,name); temp-next=0; temp-busy=0; temp-waiting = new

26、struct PCB; temp-waiting-next = NULL; /temp-waiting=0; /+ temp-occupied=0; temp-chct= chct; struct COCT * head=cocts; /进入了cocts队列 while(head-next!=0) head=head-next; head-next=temp;void addDevice(char *name,struct COCT * coct) /增加设备struct DCT * temp=(struct DCT *)malloc(sizeof(struct DCT);strcpy(tem

27、p-name,name);temp-next=0;temp-busy=0;temp-waiting = new struct PCB;temp-waiting-next = NULL;/temp-waiting=0;temp-occupied=0;temp-coct= coct;struct DCT * head=dcts;while(head-next!=0)head=head-next;head-next=temp;/添加设备+void add_dct()char newDCT10;printf(请输入新设备的名字:n);scanf(%s,newDCT);char newCOCT10;pr

28、intf(请输入要添加到的控制器的名字:n);scanf(%s,newCOCT);addDevice(newDCT,findController(newCOCT);/添加控制器void add_coct()char newCOCT10;printf(请输入新控制器的名字:n);scanf(%s,newCOCT);char newCHCT10;printf(请输入要添加到的通道的名字:n);scanf(%s,newCHCT);addController(newCOCT,findChannel(newCHCT);/添加通道void add_chct()char newCHCT10;printf(请

29、输入新的通道的名字:n);scanf(%s,newCHCT);addChannel(newCHCT);/+/+删除操作+/删除设备void deleteDCT(char nameDCT)/char nameDCT10;/int i=0;/printf(请输入要删除DCT的名字:);/scanf(%s,nameDCT);struct DCT * temp = findDCT(nameDCT);struct DCT * head = dcts;if(temp=NULL)printf(没有对应的设备!n);return ;elsewhile(head-next!=0)if(strcmp(temp-n

30、ame,head-next-name)=0)if(temp-occupied!=NULL)printf(此设备现在正在使用不能删除n);else head-next=head-next-next;/i+;break;else head=head-next;/删除控制器void deleteCOCT(char nameCOCT)struct COCT *temp=findController(nameCOCT);struct COCT *head=cocts;if(temp=NULL)printf(没有对应的控制器n);return;elsewhile(head-next!=0)if(strcm

31、p(temp-name,head-next-name)=0)if(temp-occupied!=NULL)printf(此控制器现在正在使用不能删除n);else/deleteDCT(temp-);head-next=head-next-next;break;head=head-next;/删除通道void deleteCHCT(char nameCHCT)struct CHCT *temp=findChannel(nameCHCT);struct CHCT *head=chcts;if(temp=NULL)printf(没有对应的通道n);return;elsewhile(head-next

32、!=0)if(strcmp(temp-name,head-next-name)=0)if(temp-occupied!=NULL)printf(此通道现在正在使用不能删除n);else/deleteDCT(temp-);head-next=head-next-next;/i+;break;head=head-next;/+void displayDCT()struct DCT * dct;struct COCT *coct;struct CHCT *chct = chcts;struct PCB *pcb;/-while(chct-next!=NULL)chct = chct-next;pri

33、ntf( %s(,chct-name);if(chct-occupied!=0)printf(%s,chct-occupied-name);printf();pcb = chct-waiting-next;/waiting是头结点,pcb指向队列第一个进程while(pcb!=NULL)printf(%s,pcb-name);pcb = pcb-next;printf(n);/-coct = cocts;while(coct-next!=NULL)coct = coct-next;if(strcmp(coct-chct-name,chct-name)=0)printf( %s(,coct-na

34、me);if(coct-occupied!=0)printf(%s,coct-occupied-name);printf();pcb = coct-waiting-next;while(pcb!=NULL)printf(%s,pcb-name); pcb = pcb-next;printf(n);/-dct = dcts;while(dct-next!=NULL)dct = dct-next;if(strcmp(dct-coct-name,coct-name)=0)printf( %s(,dct-name);if(dct-occupied!=0)printf(%s,dct-occupied-n

35、ame);printf();pcb = dct-waiting-next;while(pcb!=NULL)printf(%s,pcb-name); pcb = pcb-next;printf(n);/void main() dcts=(struct DCT *)malloc(sizeof(struct DCT); dcts-next=0; cocts=(struct COCT *)malloc(sizeof(struct COCT); cocts-next=0; chcts=(struct CHCT *)malloc(sizeof(struct CHCT); chcts-next=0; addChannel(chct1); addChannel(chct2); addController(coct1,findChannel(chct1); addController(coct2,findChannel(chct1); addController(coct3,findChannel(chct2); addDevice(dct1,findController(coct1); addDevice(dct2,findController(coct1); addDevice(dct3,findController(coct2); /addDe

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
搜索标签

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服