您好,欢迎访问三七文档
当前位置:首页 > 研究报告 > 综合/其它 > 设备管理算法实验报告-计算机操作系统教程(第三版)
1)2)2)I/O1.12122:(1)I/O(2)(3)(4)123SPOOLingI/OI/O1I/OI/O2I/OI/OI/OI/OI/O1(DCT,DeviceControlTable)DCTI/OI/O(SDT,SystemDeviceTable)SDTDCTDCTDCTDCT(COCT,COntrollerControlTable)I/ODMADMA(CHCT,CHannelControlTable)#includeiostream#includestring#includevectorusingnamespacestd;typedefstructnode{stringID;//stringequipment;//structnode*next;}PCB;typedefstruct{stringchannelID;//boolstate;//PCB*use;//PCB*blockqueue;//}CHCT;typedefstruct{stringcontrollerID;//boolstate;//CHCT*front;//PCB*use;//PCB*blockqueue;//}COCT;typedefstruct{chartype;//stringequipmentID;//boolstate;//COCT*front;//PCB*use;//PCB*blockqueue;//}DCT;typedefstruct{chartype;//stringequipmentID;//DCT*dct;//DCT}SDT;DCT*k=newDCT;//DCTDCT*m=newDCT;DCT*p=newDCT;DCT*t=newDCT;COCT*c1=newCOCT;COCT*c2=newCOCT;COCT*c3=newCOCT;CHCT*h1=newCHCT;CHCT*h2=newCHCT;CHCT*h3=newCHCT;intcheck(charcmd){switch(cmd){case'c'://return1;case'C':return1;case'd'://return2;case'D':return2;case'a'://return3;case'A':return3;case'f'://return4;case'F':return4;case'q':return-1;case'Q':return-1;case'p':return5;case'P':return5;default:return0;}}voidinit(vectorSDT&SDT_table){SDT_table[0].equipmentID=M;SDT_table[0].type='2';//SDT_table[0].dct=m;//DCTSDT_table[1].equipmentID=K;SDT_table[1].type='1';SDT_table[1].dct=k;SDT_table[2].equipmentID=P;SDT_table[2].type='3';SDT_table[2].dct=p;SDT_table[3].equipmentID=T;SDT_table[3].type='4';SDT_table[3].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=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-equipmentID=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;}intmain(){charcmd;DCT*temp_dct;COCT*temp_coct;CHCT*temp_chct;intl=0;stringID;stringname;vectorSDTSDT_table(4);//vectorDCTDCT_table(4);//vectorCOCTCOCT_table(3);////vectorSDT::size_typesize_SDT_table;//init(SDT_table);//DCTu=*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);COCTcu=*c1;COCT_table.push_back(cu);cu=*c2;COCT_table.push_back(cu);cu=*c3;COCT_table.push_back(cu);coutK:(1)M:(2)P:(3)T:(4)endl;coutcendl;coutdendl;coutfendl;coutaendl;while(l!=-1){cout;cincmd;l=check(cmd);if(l==0){coutendl;continue;}elseif(l==1)//{coutendl;cinID;coutendl;cinname;PCB*head=newPCB;//PCBhead-equipment=name;head-ID=ID;head-next=NULL;boolfind=false;vectorSDT::iteratorator0;for(ator0=SDT_table.begin();ator0!=SDT_table.end();ator0++){if(ator0-equipmentID==ID){find=true;//break;}}if(!find){coutendl;continue;}temp_dct=ator0-dct;if(!temp_dct-state)//{cout,endl;if(!temp_dct-blockqueue)//{temp_dct-blockqueue=head;}else//{PCB*t=temp_dct-blockqueue;while(t)t=t-next;if(!t){temp_dct-blockqueue=NULL;}elset-next=head;}}else//{temp_coct=temp_dct-front;temp_dct-state=false;temp_dct-use=head;//if(!temp_coct-state)//{cout.endl;if(!temp_coct-blockqueue)//{temp_coct-blockqueue=head;}else//{PCB*t=temp_coct-blockqueue;while(t)t=t-next;if(!t){temp_dct-blockqueue=NULL;}elset-next=head;}}else//{temp_coct-state=false;//temp_chct=temp_coct-front;temp_coct-use=head;if(!temp_chct-state)//{cout.endl;if(!temp_chct-blockqueue)//{temp_chct-blockqueue=head;}else//{PCB*t=temp_coct-blockqueue;while(t)t=t-next;if(!t){temp_dct-blockqueue=NULL;}elset-next=head;}}else//{temp_chct-use=head;temp_chct-state=false;//cout.endl;}}}}elseif(l==2)//{vectorSDT::iteratorator;vectorDCT::iteratorator1;coutendl;for(ator=SDT_table.begin();ator!=SDT_table.end();ator++){coutator-equipmentID;}cout;cinname;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.erase(ator);//ator=SDT_table.begin();/*for(ator=SDT_table.begin();ator!=SDT_table.end();ator++)coutator-equipmentID;coutendl;*/if(temp-use){if(temp-use-equipment==name)//{if(!temp-blockqueue)//{temp-state=true;temp-use=NULL;}else//{PCB*tt=temp-blockqueue;temp-blockqueue-next=tt-next;temp-use=tt;tt-next=NULL;}}else//{temp-blockqueue=NULL;}}ator1-blockqueue=NULL;ator1-front=NULL;ator1-use=NULL;vectorDCT::iteratorator2;vectorDCTD;for(ator2=DCT_table.begin();ator2!=DCT_table.end();ator2++){if(ator2!=ator1)D.push_back(*ator2);}DCT_table=D;//ator1=DCT_table.erase(ator1);//break;}}if(ator==SDT_table.end())//{coutendl;}else{coutendl;}}elseif(l==3)//{SDTSDT_add;DCTDCT_add;intselect;cout;cinDCT_add.equipmentID;SDT_add.equipmentID=DCT_add.equipmentID;cout;cinDCT
本文标题:设备管理算法实验报告-计算机操作系统教程(第三版)
链接地址:https://www.777doc.com/doc-8695591 .html