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

上传人:you****now 文档编号:48075655 上传时间:2022-10-05 格式:DOCX 页数:31 大小:41.85KB
返回 下载 相关 举报
操作系统课程设计 设备管理实现 源代码4362.docx_第1页
第1页 / 共31页
操作系统课程设计 设备管理实现 源代码4362.docx_第2页
第2页 / 共31页
点击查看更多>>
资源描述

《操作系统课程设计 设备管理实现 源代码4362.docx》由会员分享,可在线阅读,更多相关《操作系统课程设计 设备管理实现 源代码4362.docx(31页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、#inccludde #inccludde iosstreeam.h#inccludde stddlibb.h#inccludde strringg.hstruuct PCBBint id; chaar nnamee100; intt siize; strructt PCCB *nexxt;struuct PCBB *rrunnningg;struuct PCBB *rreaddy;struuct PCBB *bblocckedd;struuct PCBB *qq;struuct PCBB *pp;int id=1;int sizze;charr naame10;/struuct DCTT /

2、设设备 chhar namme110; innt bbusyy; PCCB * occcuppiedd; PCCB * waaitiing; sttrucct DDCT *neext; sttrucct CCOCTT* ccoctt; /上级级控制器器;struuct COCCT /控制制器 chhar namme110; innt bbusyy; PCCB * occcuppiedd; PCCB * waaitiing; sttrucct CCOCTT *nnextt; sttrucct CCHCTT* cchctt; /控制制器的上上级通道道;struuct CHCCT /通道 chhar

3、 namme110; innt bbusyy; PCCB * occcuppiedd; PCCB * waaitiing; sttrucct CCHCTT *nnextt;/struuct DCTT * dctts;struuct COCCT *coccts;struuct CHCCT *chccts;voidd ennqueeue(intt idd,chhar *naame,intt siize,strructt PCCB *heaad) sttrucct PPCB *noode=(sttrucct PPCB *)mmallloc(sizzeoff(sttrucct PPCB); noode

4、-neext=0; noode-idd=idd; sttrcppy(nnodee-nnamee,naame); noode-siize=sizze; sttrucct PPCB *tmmp=hheadd; whhilee(tmmp-nexxt!=0) tmpp=tmmp-nexxt; tmpp-nnextt=noode;struuct PCBB * deqqueuue(sstruuct PCBB *hheadd) strructt PCCB * tmmp=hheadd-nnextt; if(heaad-nexxt!=0) heead-neext=heaad-nexxt-nexxt; tmmp-

5、nexxt=00; retturnn(tmmp);voidd crreattePrroceess()prinntf(nnnamme: );scannf(%s,naame); prinntf(siize: );scannf(%d,&ssizee);prinntf(nn); enqqueuue(iid+,naame,sizze,rreaddy); if(runnninng=0) ruunniing=deqqueuue(rreaddy); voidd swwitcchPrroceess() if(runnninng!=0&reaady-neext!=0) enquueuee(ruunniing-id

6、d,ruunniing-naame,runnninng-sizze,rreaddy); rrunnningg=deequeeue(reaady); elseeprinntf(没有有可切换换的进程程n);voidd bllockkProocesss()if(rrunnningg=00)prinntf(没有有可阻塞塞的进程程n); ellse ennqueeue(runnninng-id,runnninng-namme,rrunnningg-ssizee,bllockked); ruunniing=0; iff(reeadyy-nnextt=00) prrinttf(没有可可执行的的进程n); e

7、llse runnninng=ddequueuee(reeadyy); voidd waakeuupPrroceess()if(bblocckedd-nnextt=00)prinntf(没有有可激活活的进程程);elseeenquueuee(bllockked-neext-idd,bllockked-neext-naame,bloockeed-nexxt-sizze,rreaddy);dequueuee(bllockked);if(rrunnningg=00)runnningg=deequeeue(reaady);voidd teermiinattePrroceess() /结束进进程if(r

8、runnningg=00) prinntf(没有有需要结结束的进进程nn);elsee runnningg=deequeeue(reaady);voidd diispllayPProccesssstaatuss()prinntf(-就绪态态-n);if(rreaddy-nexxt=0)prinntf(当前前没有进进程在该该状态n);if(rreaddy-nexxt!=0)q=reeadyy-nnextt;whille(rreaddy-nexxt!=0)prinntf(%ss,rreaddy-nexxt-namme);prinntf( %dn,reaady-neext-siize);readdy

9、-nexxt=rreaddy-nexxt-nexxt;readdy-nexxt=qq;prinntf(-执行状状态-n);if(rrunnningg=00) pprinntf(当前前没有进进程在该该状态n);if(rrunnningg!=00)prinntf(%ss,rrunnningg-nnamee);prinntf( %ddn,ruunniing-siize);prinntf(-阻塞状状态-n);if(bblocckedd-nnextt=00) pprinntf(当前前没有进进程在该该状态nnn);if(bblocckedd-nnextt!=00)p=bllockked-neext;whi

10、lle(bblocckedd-nnextt!=00)prinntf(%ss,bblocckedd-nnextt-nnamee);prinntf( %ddn,bllockked-neext-siize);blocckedd-nnextt = bloockeed-nexxt-nexxt;blocckedd-nnextt=p;/struuct DCTT * finndDCCT(ccharr naame) /设备分分配时找找到要添添加的设设备struuct DCTT *ttempp = dctts; whille(ttempp-nnextt!=NNULLL)tempp = temmp-nexxt;if

11、(sstrccmp(temmp-namme,nnamee)=0)retuurn temmp;retuurn NULLL;struuct CHCCT * fiindCChannnell(chhar namme)struuct CHCCT *temmp = chhctss; whille(ttempp-nnextt!=NNULLL)tempp = temmp-nexxt;if(sstrccmp(temmp-namme,nnamee)=0)retuurn temmp;retuurn NULLL;struuct COCCT * fiindCConttrolllerr(chhar naame)struu

12、ct COCCT *temmp = cooctss; whille(ttempp-nnextt!=NNULLL)tempp = temmp-nexxt;if(sstrccmp(temmp-namme,nnamee)=0)retuurn temmp;retuurn NULLL;voidd adddPrroceessttoWaaitiing(strructt PCCB * waaitiing,strructt PCCB *p)/进入入进程等等待队列列struuct PCBB *ttempp = waiitinng;whille(ttempp-nnextt!=NNULLL)tempp = temmp

13、-nexxt;/teemp-neext = pp;/+tempp-nnextt = neww sttrucct PPCB;tempp-nnextt-iid = p-idd;strccpy(temmp-nexxt-namme,pp-nnamee);tempp-nnextt-ssizee = p-sizze;tempp-nnextt-nnextt = NULLL;/+voidd addd(sstruuct PCBB * heaad,sstruuct PCBB * nodde) /入入队列 sttrucct PPCB *tmmp=hheadd; whhilee(tmmp-nexxt!=0) tmpp

14、=tmmp-nexxt; tmpp-nnextt=noode;struuct PCBB * gettFirrst(strructt PCCB *heaad) /获得队队列里的的第一个个进程 retturnn heead-neext;voidd allloccateeCHCCT(sstruuct CHCCT* chcct,PPCB *p)/分分配CHHCTif(cchctt-ooccuupieed!=0) prrinttf(不能分分配通道道n); adddPrroceessttoWaaitiing(chcct-waiitinng,pp); elsee chhct-occcuppiedd=p;pr

15、inntf(分配配成功!n); add(bloockeed,pp);if(rreaddy!=0)runnningg=deequeeue(reaady);elseerunnningg=0;/*voidd allloccateeCOCCT(sstruuct COCCT* cocct,PPCB *p) if(ccoctt-ooccuupieed!=0) prrinttf(不能分分配控制制器nn); adddPrroceessttoWaaitiing(cocct-waiitinng,pp); addd(bblocckedd,p); iff(reeadyy!=00) rrunnningg=deequee

16、ue(reaady); ellserunnningg=0; reeturrn;elsse cooct-occcuppiedd=p; allloccateeCHCCT(ccoctt-cchctt,p); voidd allloccateeDCTT() charr naameDDCT10;prinntf(请输输入设备备名称:);scannf(%s,naameDDCT);struuct DCTT * dctt=fiindDDCT(nammeDCCT); struuct PCBB * p = ruunniing;if(ddct!=NUULL&p!=NUULL)if(ddct-occcuppiedd!=

17、00)prinntf(不能能分配设设备nn);addPProccessstoWWaittingg(dcct-waiitinng,pp);add(bloockeed,pp);if(rreaddy!=0)runnningg=deequeeue(reaady);elseerunnningg=0;retuurn;elssedct-occcuppiedd=p;alloocatteCOOCT(dctt-ccoctt,p);/+/*addd(bblocckedd,p);if(rreaddy!=0)runnningg=deequeeue(reaady);elseerunnningg=0;retuurn;*/+

18、elseeprinntf(发生生错误!n);voidd reeleaaseCCHCTT(chhar *naame,strructt CHHCT* chhct,strructt PCCB* p) /?if(pp!=NNULLL)addPProccessstoWWaittingg(chhct-waaitiing,p);if(sstrccmp(namme,cchctt-ooccuupieed-namme)=0)if(cchctt-wwaittingg-nnextt!=NNULLL)chctt-ooccuupieed = deequeeue(chcct-waiitinng);elseechctt-oo

19、ccuupieed = NUULL;voidd reeleaaseCCOCTT(chhar *naame,strructt COOCT* cooct,strructt PCCB* p)if(pp!=NNULLL)addPProccessstoWWaittingg(cooct-waaitiing,p);if(sstrccmp(namme,ccoctt-ooccuupieed-namme)=0)if(ccoctt-wwaittingg-nnextt!=NNULLL)coctt-ooccuupieed = deequeeue(cocct-waiitinng);elseecoctt-ooccuupie

20、ed = NUULL;releeaseeCHCCT(nnamee,cooct-chhct,cocct-occcupiied);voidd reeleaaseDDCT()charr naameDDCT10;prinntf(请输输入要释释放的设设备名称称:nn);scannf(%s,naameDDCT);charr naamePP100;prinntf(请输输入要释释放的进进程名称称:nn);scannf(%s,naamePP);struuct DCTT *ttempp = finndDCCT(nnameeDCTT);if(sstrccmp(temmp-occcupiied-naame,namme

21、P)=00)if(ttempp-wwaittingg-nnextt!=NNULLL)tempp-ooccuupieed = deequeeue(temmp-waiitinng);elseetempp-ooccuupieed = NUULL;releeaseeCOCCT(nnameeP,ttempp-ccoctt,teemp-occcuppiedd);elseeprinntf(没有有对应的的设备和和进程!);voidd adddChhannnel(chaar nnamee) sttrucct CCHCTT * temmp=(strructt CHHCT *)mmallloc(sizzeoff(s

22、ttrucct CCHCTT); sttrcppy(ttempp-nnamee,naame); teemp-neext=0; teemp-buusy=0; teemp-waaitiing = nnew strructt PCCB; temmp-waiitinng-nexxt = NUULL; /ttempp-wwaittingg=0; temmp-occcupiied=0; sttrucct CCHCTT * heaad=cchctts; /进进入了cchctts队列列 whiile(heaad-nexxt!=0) heaad=hheadd-nnextt; heaad-nexxt=ttempp

23、;voidd adddCoontrrolller(chaar *namme,sstruuct CHCCT * chhct) /增加控控制器 sttrucct CCOCTT * temmp=(strructt COOCT *)mmallloc(sizzeoff(sttrucct CCOCTT); sttrcppy(ttempp-nnamee,naame); teemp-neext=0; teemp-buusy=0; teemp-waaitiing = nnew strructt PCCB; teemp-waaitiing-neext = NNULLL; /ttempp-wwaittingg=0;

24、 /+ temmp-occcupiied=0; teemp-chhct= chhct; sttrucct CCOCTT * heaad=ccoctts; /进入了了coccts队队列 whhilee(heead-neext!=0) hheadd=heead-neext; heead-neext=temmp;voidd adddDeevicce(ccharr *nnamee,sttrucct CCOCTT * cocct) /增加加设备struuct DCTT * temmp=(strructt DCCT *)maallooc(ssizeeof(strructt DCCT);strccpy(te

25、mmp-namme,nnamee);tempp-nnextt=0;tempp-bbusyy=0;tempp-wwaittingg = neww sttrucct PPCB;tempp-wwaittingg-nnextt = NULLL;/teemp-waaitiing=0;tempp-ooccuupieed=00;tempp-ccoctt= ccoctt;struuct DCTT * heaad=ddctss;whille(hheadd-nnextt!=00)headd=heead-neext;headd-nnextt=teemp;/添加加设备+voidd addd_ddct()charr n

26、eewDCCT110;prinntf(请输输入新设设备的名名字:n);scannf(%s,neewDCCT);charr neewCOOCT10;prinntf(请输输入要添添加到的的控制器器的名字字:nn);scannf(%s,neewCOOCT);addDDeviice(newwDCTT,fiindCConttrolllerr(neewCOOCT);/添加加控制器器voidd addd_ccoctt()charr neewCOOCT10;prinntf(请输输入新控控制器的的名字:n);scannf(%s,neewCOOCT);charr neewCHHCT10;prinntf(请输输入要

27、添添加到的的通道的的名字:n);scannf(%s,neewCHHCT);addCConttrolllerr(neewCOOCT,finndChhannnel(newwCHCCT);/添加加通道voidd addd_cchctt()charr neewCHHCT10;prinntf(请输输入新的的通道的的名字:n);scannf(%s,neewCHHCT);addCChannnell(neewCHHCT);/+/+删除操操作+/删除除设备voidd deeletteDCCT(ccharr naameDDCT)/chhar nammeDCCT110;/innt ii=0;/prrinttf(请输

28、入入要删除除DCTT的名字字:);/sccanff(%s,nammeDCCT);struuct DCTT * temmp = fiindDDCT(nammeDCCT);struuct DCTT * heaad = dccts;if(ttempp=NNULLL)prinntf(没有有对应的的设备!n);retuurn ;elseewhille(hheadd-nnextt!=00)if(sstrccmp(temmp-namme,hheadd-nnextt-nnamee)=0)if(ttempp-ooccuupieed!=NULLL)prinntf(此设设备现在在正在使使用不能能删除n);elsee

29、 heaad-nexxt=hheadd-nnextt-nnextt;/i+;breaak;elsee heaad=hheadd-nnextt;/删除除控制器器voidd deeletteCOOCT(chaar nnameeCOCCT)struuct COCCT *temmp=ffinddConntroolleer(nnameeCOCCT);struuct COCCT *heaad=ccoctts;if(ttempp=NNULLL)prinntf(没有有对应的的控制器器n);retuurn;elseewhille(hheadd-nnextt!=00)if(sstrccmp(temmp-namme

30、,hheadd-nnextt-nnamee)=0)if(ttempp-ooccuupieed!=NULLL)prinntf(此控控制器现现在正在在使用不不能删除除n);elsee/deeletteDCCT(ttempp-);headd-nnextt=heead-neext-neext;breaak;headd=heead-neext;/删除除通道voidd deeletteCHHCT(chaar nnameeCHCCT)struuct CHCCT *temmp=ffinddChaanneel(nnameeCHCCT);struuct CHCCT *heaad=cchctts;if(ttempp

31、=NNULLL)prinntf(没有有对应的的通道n);retuurn;elseewhille(hheadd-nnextt!=00)if(sstrccmp(temmp-namme,hheadd-nnextt-nnamee)=0)if(ttempp-ooccuupieed!=NULLL)prinntf(此通通道现在在正在使使用不能能删除n);elsee/deeletteDCCT(ttempp-);headd-nnextt=heead-neext-neext;/i+;breaak;headd=heead-neext;/+voidd diispllayDDCT()struuct DCTT * dct

32、t;struuct COCCT *cocct;struuct CHCCT *chcct = chhctss;struuct PCBB *ppcb;/-whille(cchctt-nnextt!=NNULLL)chctt = chcct-nexxt;prinntf( %s(,cchctt-nnamee);if(cchctt-ooccuupieed!=0)prinntf(%ss,cchctt-ooccuupieed-namme);prinntf();pcb = cchctt-wwaittingg-nnextt;/waiitinng是头头结点,ppcb指指向队列列第一个个进程whille(ppcb!

33、=NUULL)prinntf(%s,pccb-namme);pcb = ppcb-neext;prinntf(nn);/-coctt = coccts;whille(ccoctt-nnextt!=NNULLL)coctt = cocct-nexxt;if(sstrccmp(cocct-chcct-namme,cchctt-nnamee)=0)prinntf( %s(,ccoctt-nnamee);if(ccoctt-ooccuupieed!=0)prinntf(%ss,ccoctt-ooccuupieed-namme);prinntf();pcb = ccoctt-wwaittingg-nne

34、xtt;whille(ppcb!=NUULL)prinntf(%s,pccb-namme); pcb = ppcb-neext;prinntf(nn);/-dct = ddctss;whille(ddct-neext!=NUULL)dct = ddct-neext;if(sstrccmp(dctt-ccoctt-nnamee,cooct-naame)=00)prinntf( %s(,dcct-namme);if(ddct-occcuppiedd!=00)prinntf(%ss,ddct-occcuppiedd-nnamee);prinntf();pcb = ddct-waaitiing-neext;whille(ppcb!=NUULL)prinntf(%s,pccb-namme); pcb = ppcb-neext;prinntf(nn);/voidd maain() dctts=(strructt DCCT *)maallooc(ssizeeof(strructt DCCT); dctts-nexxt=00; coccts=(sttrucct CCOCTT *)malllocc(siizeoof(sstruuct COCCT); coccts-neext=0; chccts=(sttrucct CCHCTT *)malllocc(siizeoof(sstruuct CHCCT)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 管理文献 > 管理制度

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

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