版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
操作系統(tǒng)課程設(shè)計(jì)報(bào)告題目:一種小型操作系統(tǒng)班級(jí):計(jì)122(杏)學(xué)號(hào):姓名:賈蘇日期:/06/23實(shí)驗(yàn)平臺(tái)(1)軟件平臺(tái):開發(fā)系統(tǒng)平臺(tái):Windows7(64)Microsoftvisualc++6.0測(cè)試系統(tǒng)平臺(tái):Windows7(64)硬件平臺(tái):cpu:AMDA6-3420APU內(nèi)存:4GB硬盤:500G2.所需實(shí)現(xiàn)功能及相應(yīng)闡述:(1)進(jìn)程調(diào)度管理為了貼切現(xiàn)實(shí)中os,采用RR(輪轉(zhuǎn)調(diào)度算法),且不提供顧客顯式選取調(diào)度算法,即對(duì)顧客是透明?,F(xiàn)實(shí)中解決器主頻為1Ghz~3Ghz,選用中間點(diǎn)為1.5Ghz,得時(shí)間片大小為0.7ns,為以便計(jì)算*10,則時(shí)間片大小定為7ns。假設(shè)進(jìn)程之間調(diào)度和切換不耗費(fèi)cpu時(shí)間。(2)死鎖檢測(cè)與解決檢測(cè)固然采用是銀行家算法解決:讓顧客選取kill一種進(jìn)程,釋放她所占有所有資源。(3)虛擬分頁(yè)調(diào)度管理虛擬分頁(yè):給出是邏輯值訪問(wèn)磁盤將那個(gè)數(shù)據(jù)塊放入到內(nèi)存中內(nèi)存中地址采用一定算法相相應(yīng)于磁盤地址。特規(guī)定訪存采用是按字節(jié)尋址內(nèi)存大小128KB外存大小1MB即整個(gè)系統(tǒng)可以提供1MB邏輯地址空間供進(jìn)程進(jìn)行訪問(wèn)(在地址總線足夠掃描內(nèi)存狀況下)。虛擬地址映射采用:直接映射法規(guī)定8kB為一種頁(yè)面,故內(nèi)存有16個(gè)頁(yè)面,外存有128個(gè)頁(yè)面。如果產(chǎn)生了內(nèi)存已滿,便會(huì)產(chǎn)生缺頁(yè)中斷,裁減采用FIFO算法,運(yùn)用一種隊(duì)列來(lái)做。某些內(nèi)外存相應(yīng)表00,128,2*128+0.......11,129,2*128+1.......22,130,2*128+2.......16127,128+16,2*128+16.........(4)I/O中斷解決設(shè)中斷來(lái)自兩個(gè)方面:1.DMA輸送開始和結(jié)束時(shí)中斷設(shè)定一種宏定義為DMA一次傳播數(shù)據(jù)量大小->DmaNum假定為10kb每次DMA開始:耗費(fèi)1nscpu時(shí)間進(jìn)行中斷解決DMA結(jié)束:耗費(fèi)2nscpu時(shí)間進(jìn)行中斷解決由操作系統(tǒng)課程知,DMA傳播數(shù)據(jù)時(shí)不需要CPU干預(yù)。隨機(jī)中斷發(fā)生外部隨機(jī)中斷,cpu無(wú)條件及時(shí)響應(yīng),并執(zhí)行中斷解決程序,同樣假設(shè)中斷解決程序調(diào)度和切換不耗費(fèi)cpu時(shí)間。(5)內(nèi)存地址越界或內(nèi)存局限性進(jìn)程訪問(wèn)內(nèi)存時(shí)超過(guò)了進(jìn)程所要最大值,此時(shí)發(fā)生中斷,已達(dá)到內(nèi)存保護(hù)功能。內(nèi)存局限性時(shí)即為當(dāng)前動(dòng)態(tài)地址重定位寄存器中值+進(jìn)程所需內(nèi)存大小超過(guò)了內(nèi)存上限,此時(shí)進(jìn)行內(nèi)存緊湊,同步修改被移動(dòng)進(jìn)程中各個(gè)關(guān)于參數(shù)。3.總體設(shè)計(jì)開始開始內(nèi)存管理查看運(yùn)營(yíng)狀況開始運(yùn)營(yíng)外存空間查看查看cpu運(yùn)營(yíng)內(nèi)存空間查看死鎖檢測(cè)與解除進(jìn)程信息查看內(nèi)存管理查看運(yùn)營(yíng)狀況開始運(yùn)營(yíng)外存空間查看查看cpu運(yùn)營(yíng)內(nèi)存空間查看死鎖檢測(cè)與解除進(jìn)程信息查看4.程序所需數(shù)據(jù)構(gòu)造及其抽象過(guò)程先定義本次操作系統(tǒng)外設(shè)資源,假設(shè)有A類資源10個(gè),B類資源5個(gè),C類資源6個(gè)->NeedRescourse;作業(yè)中各個(gè)進(jìn)程都需要一種代號(hào)->ProcessName,各個(gè)進(jìn)程到來(lái)時(shí)間不同,故需要記錄一下->ArriveTime,每個(gè)進(jìn)程所需要cpu時(shí)間是不夠->NeedCpuTime,每個(gè)進(jìn)程所需內(nèi)存空間大小是不同樣->NeedMem。各個(gè)進(jìn)程中任務(wù)是不同故需要預(yù)先設(shè)定本進(jìn)程中所要執(zhí)行操作類型->OpKind,如果是計(jì)算型直接給出所需要cpu時(shí)間即可,如果是I/O型還需要給出所傳播數(shù)據(jù)量大小->NeedTranDataNum,在此可以給OpKind做一種union型構(gòu)造。多道程序程序在運(yùn)營(yíng)過(guò)程中需要對(duì)進(jìn)程所需內(nèi)存地址進(jìn)行動(dòng)態(tài)地址重定位,故在系統(tǒng)之中需要設(shè)立一種動(dòng)態(tài)地址重定位寄存器,其中內(nèi)容是下次進(jìn)程可以使用內(nèi)存始址->DynReg。抽象成果:structProcess{ charProcessName[10];//進(jìn)程名字 intArriveTime;//ns級(jí)別 intNeedCpuTime;//此進(jìn)程所需要時(shí)間 intNeedMem;//所需要cpu時(shí)間 FlagForOpOpKind;//用于批示是何種操作 intNeedTranDataNum;//給IO用數(shù)據(jù)塊 intOpCpus;//計(jì)算類型操作所需cpu時(shí)間 intNeedRescourse[3];//需要資源數(shù)目NULL代表不需要使用 Process*next;};5.詳細(xì)設(shè)計(jì)1.進(jìn)程信息查看依次遍歷所有鏈表,并將它們信息依次打印出來(lái)。實(shí)現(xiàn)函數(shù)名:voidShowProcessInfo()2.死鎖檢測(cè)和解除假定本系統(tǒng)中各個(gè)所需資源均是獨(dú)占型資源,在進(jìn)程運(yùn)營(yíng)過(guò)程中不再釋放,故只需要遍歷鏈表將各個(gè)進(jìn)程中所需資源記錄出來(lái),只要不不不大于系統(tǒng)中預(yù)設(shè)即可,一旦進(jìn)程所需資源不不大于系統(tǒng)中最大量,予以顧客選取kill一進(jìn)程,已達(dá)到釋放資源目。死鎖檢測(cè)函數(shù):voidDeedLock() voidDeedLock_LookNeedRescourse()死鎖解除函數(shù):voidDeedLock_KillProcess()內(nèi)存空間查看查看各個(gè)進(jìn)程所占用內(nèi)存空間,借助于DynReg這個(gè)全局變量實(shí)行內(nèi)存空間動(dòng)態(tài)重定位。實(shí)現(xiàn)函數(shù):voidLookMem()查看CPU運(yùn)營(yíng)以CPU角度,查看作業(yè)運(yùn)營(yíng)狀況,實(shí)現(xiàn)函數(shù):voidLookCpu() voidLookCpu_ShowRunningProcess()外存空間查看外存空間是顧客工作區(qū)間,故只要遍歷整個(gè)進(jìn)程鏈表,記錄出所有進(jìn)程占有所有空間即可。實(shí)現(xiàn)函數(shù):voidLookDiskMem()查看運(yùn)營(yíng)查看系統(tǒng)運(yùn)營(yíng)中各個(gè)資源使用狀況:實(shí)現(xiàn)函數(shù): voidShowRunningProcess() voidShowRunningProcess_CalculateCpuNeed(int*,int)內(nèi)存管理缺頁(yè)調(diào)度算法:FIFO(借助于循環(huán)隊(duì)列實(shí)現(xiàn))實(shí)現(xiàn)函數(shù):voidMemToDiskMem()6.程序運(yùn)營(yíng)和調(diào)試1.打開程序初始界面:按系統(tǒng)提示輸入進(jìn)程數(shù),及其有關(guān)各個(gè)參數(shù)2.輸入完畢后主界面:顧客可以按下有關(guān)選取鍵實(shí)行關(guān)于各個(gè)操作。按下1查看各個(gè)進(jìn)程信息可以看到剛剛輸入各個(gè)進(jìn)程關(guān)于信息4.按下2按下3查看運(yùn)營(yíng)時(shí)CPU使用狀況可見此時(shí)系統(tǒng)是安全。系統(tǒng)出差提示按下1顯示當(dāng)前各個(gè)進(jìn)程所需資源然后kill進(jìn)程1后在查看一下作業(yè)中進(jìn)程,發(fā)現(xiàn)被kill進(jìn)程沒(méi)有,實(shí)現(xiàn)了此功能。按下4查看內(nèi)存使用狀況按下5查看外存空間按下6查看運(yùn)營(yíng)狀況按下7產(chǎn)看內(nèi)存使用狀況沒(méi)有產(chǎn)生缺頁(yè)產(chǎn)生缺頁(yè)10.按下9退出此系統(tǒng)7.遇到問(wèn)題自己編寫映射表相稱困難,一度想改用Java語(yǔ)言,在于對(duì)C++語(yǔ)言理解不夠。出錯(cuò)解決沒(méi)有完全做完,做不夠精細(xì),諸多地方直接結(jié)束對(duì)顧客輸入數(shù)據(jù)做類型檢查不夠充分deletejob時(shí)總是浮現(xiàn)系統(tǒng)錯(cuò)誤,后debug發(fā)現(xiàn),由于對(duì)象之中存在不為空指針,導(dǎo)致出錯(cuò),故再釋放指針?biāo)伎臻g后系統(tǒng)正常運(yùn)營(yíng)。源代碼#include<iostream>#include<cstring>#include<windows.h>#include<cstdlib>#include"CirQueue.h"http://循環(huán)隊(duì)列頭文獻(xiàn)usingnamespacestd;#defineMAXMEM128//定義本次操作系統(tǒng)最大內(nèi)存容量#defineMAXDISKMEM1024//定義本次操作系統(tǒng)最大外存容量#defineYE10//定義本次操作系統(tǒng)分頁(yè)大小并以此實(shí)現(xiàn)虛擬存儲(chǔ)intUsedMAXMEM=0;intUsedMAXDISKMEM=0;//定義進(jìn)程也許用到外部資源#defineA10#defineB5#defineC6//cpu#defineRR7//定義時(shí)間片大小為7ns#defineBEFOREDMA1//DMA之前所需cpu時(shí)間#defineAFTERDMA2//DMA之后所需cpu時(shí)間#defineONEDMANUM10//DMA一次最多傳送10kb數(shù)據(jù)enumFlagForOp{ IO,Calculate,others};intDynReg=0;//定義用于描述動(dòng)態(tài)地址重定位寄存器全局變量structProcess{ charProcessName[10];//進(jìn)程名字 intArriveTime;//ns級(jí)別 intNeedCpuTime;//此進(jìn)程所需要時(shí)間 intNeedMem;//所需要cpu時(shí)間 FlagForOpOpKind;//用于批示是何種操作 intNeedTranDataNum;//給IO用數(shù)據(jù)塊 intOpCpus;//計(jì)算類型操作所需cpu時(shí)間 //假設(shè)others不需要其她各個(gè)操作。 intNeedRescourse[3];//需要資源數(shù)目NULL代表不需要使用0——a.... Process*next;};classJOB{ Process*p; Process*head; Process*head1;//建立一種備用鏈表 // Process*wait,*runing;//wait為等待鏈表running是正在運(yùn)營(yíng)進(jìn)程public: JOB(){ head1=p=head=NULL;//初始化為空 cout<<"Pleasewaiting.TheSystemisinitial."<<endl; Sleep();//暫停一秒maybeSleep() cout<<"Systemisalready.Nowyoushouldenterinformationofyoujob."<<endl; intn; cout<<"enteryourjob'sprocessnum."<<endl; cin>>n; while(n){ p=newProcess(); cout<<"pleaseenterthenameofprocess."<<endl; cin>>p->ProcessName; cout<<"pleaseenterthearrivetimeofprocess."<<endl; cin>>p->ArriveTime; cout<<"pleaseentertheNeedCpuTimeofprocess."<<endl; cin>>p->NeedCpuTime; cout<<"pleaseentertheNeedMemofprocess."<<endl; cin>>p->NeedMem; while(p->NeedMem>128){ cout<<"ThisSystemcan'tnotacceptyourjob!Maybeyourjobistoolarge!Pleaseenteranum<128"<<endl; cin>>p->NeedMem; } cout<<"pleaseentertheoperationofprocess.0toTranDiskNum,1tocpu"<<endl; intnn; cin>>nn; if(nn==0){ cout<<"pleaseentertheNeedTranDataNum."<<endl; cin>>p->NeedTranDataNum; p->OpKind=IO; }else{ cout<<"pleaseentertheOpCpus."<<endl; cin>>p->OpCpus; p->OpKind=Calculate; } cout<<"PLeaseentertheA,BorCyouneed"<<endl; for(inti=0;i<3;i++){ cin>>p->NeedRescourse[i]; } p->next=NULL;//尾結(jié)點(diǎn)為空表達(dá)一種節(jié)點(diǎn)完畢下面進(jìn)行插入鏈表工作 head=SortLinkTable(head,p); n--; }//while LinkCopy();//將本次整頓好鏈表依次賦值賦給備用鏈表 Provide_Same_Process_Name();//檢查重名現(xiàn)象 } voidProvide_Same_Process_Name(); voidVisitLinkTable(); Process*SortLinkTable(Process*,Process*); voidBeginRunning(); voidShowProcessInfo(); voidDeedLock(); voidDeedLock_KillProcess(); voidDeedLock_LookNeedRescourse(); voidLookCpu(); voidLookCpu_ShowRunningProcess(); voidLookMem(); voidShowRunningProcess(); voidShowRunningProcess_CalculateCpuNeed(int*,int); voidLookDiskMem(); voidLookMem_ChangeMem(); boolCheckMem(); voidLookDiskMem_Change(); voidLinkCopy();voidMemToDiskMem();~JOB(){ deletehead; deletehead1; deletep;}};JOB*job;//設(shè)立全局變量voidJOB::Provide_Same_Process_Name(){system("cls");charbuffer[10];Process*temp=head1;Process*temp1=head1;while(temp){ temp1=temp->next; while(temp1){ if(strcmp(temp->ProcessName,temp1->ProcessName)==0){ cout<<"Mini_OperationSystemhaddetectthesamenameprocessinyourjob!"<<endl; cout<<"ThisSystemcan'tacceptthissitution.PleaseRenameyourProcess!\nThanksforyourcorporation!"<<endl;cout<<"ThisisALLyourprocessname:"<<endl;VisitLinkTable(); cout<<"Enter1torenametheformer,0torenamethelater!"<<endl; intn=0; cin>>n; cout<<"NowEnternewName:"<<endl; if(n==0){ cin>>buffer; strcpy(temp1->ProcessName,buffer); }else{cin>>buffer; strcpy(temp->ProcessName,buffer); } }//endif temp1=temp1->next; }//endwhiletemp1 temp=temp->next;}//while}voidAgainEnterJOB(){ system("cls"); deletejob; job=newJOB();}voidJOB::VisitLinkTable(){//不加JOB前綴時(shí)候編譯但是加上代表此函數(shù)是JOBclass之中 while(head1){ cout<<head1->ProcessName<<endl; head1=head1->next; }cout<<"\nNow,YoucanseeTheListtocheckout."<<endl;}voidJOB::LinkCopy(){Process*temp=NULL,*temp2=head;if(head1==NULL){cout<<"LinkCopy()isHere!"<<endl;}if(head1)//不為空時(shí)將其下一種置為空head1->next=NULL;head1=NULL;while(temp2){ //applyanewnode temp=newProcess();strcpy(temp->ProcessName,temp2->ProcessName); temp->ArriveTime=temp2->ArriveTime;temp->NeedCpuTime=temp2->NeedCpuTime; temp->NeedMem=temp2->NeedMem; if(temp2->OpKind==IO){ temp->OpKind=IO;temp->NeedTranDataNum=temp2->NeedTranDataNum; }else{ temp->OpKind=Calculate;temp->OpCpus=temp2->OpCpus; } for(inti=0;i<3;i++){temp->NeedRescourse[i]=temp2->NeedRescourse[i]; } //applyendtemp->next=NULL; //cout<<"copyisright!"<<endl;if(head1==NULL){head1=temp; }else{ Process*k=head1;while(k->next){//尋找到最后一種節(jié)點(diǎn)不斷循環(huán)退不出去 k=k->next; } k->next=temp; } //cout<<"copyisright!"<<endl;temp2=temp2->next;}//whileif(head1==NULL)cout<<"LinkCopy()isout!"<<endl;system("pause");}voidJOB::MemToDiskMem(){ system("cls");CirQueue<int>q(16);//一共定義16個(gè)頁(yè)面q.EnQueue(e); int*Mem; intcount=0;//記錄下進(jìn)程數(shù)目 Process*temp_head1=head1; while(temp_head1){count++; temp_head1=temp_head1->next; }temp_head1=head1;Mem=newint[count];inttemp_count=0; while(temp_head1){intBegin=0; cout<<"Process:"<<temp_head1->ProcessName<<"memeryusesituation:"<<endl;Begin+=temp_head1->NeedMem; intk=0;//所需頁(yè)面數(shù)目 if(Begin%YE==0){k=Begin/YE; }else{k=Begin/YE+1; }Mem[temp_count++]=k; cout<<k<<"頁(yè)被占用!"<<endl; temp_head1=temp_head1->next; }//endwhilecout<<endl; temp_head1=head1; cout<<"Wanttosee缺頁(yè)調(diào)度過(guò)程Y/N."<<endl; charoption; inttotal=0,AllTotal=0; cin>>option; if(option=='y'||option=='Y'){ for(inti=0;i<count;i++){ AllTotal+=Mem[i]; for(intj=0;j<Mem[i];j++){if(q.EnQueue(true)){ temp_count=0; while(temp_count<i){temp_head1=temp_head1->next; temp_count++; }cout<<"Process:"<<temp_head1->ProcessName<<"needmemisloading.ok"<<endl; temp_head1=head1; }else{temp_count=0; while(temp_count<i){temp_head1=temp_head1->next; temp_count++; }cout<<"Process:"<<temp_head1->ProcessName<<"needmemisloadingerror缺頁(yè)調(diào)度"<<endl; temp_head1=head1; total++;boolflag=q.DeQueue(); if(q.EnQueue(true)){cout<<"Process:"<<temp_head1->ProcessName<<"needmemisloadingok缺頁(yè)調(diào)度"<<endl; } } }//for2 cout<<endl; }//for1} cout<<"一共產(chǎn)生了:"<<total<<"次缺頁(yè)中斷.\n"<<"缺頁(yè)中斷率為:"<<(float)total/AllTotal<<"%"<<endl; system("pause");}voidJOB::LookCpu_ShowRunningProcess(){ system("cls"); intNowTime=0; Process*run=head1;//暫時(shí)試用一下最后需要?dú)w還為NULL Process*wait=head1;//dsvrfgvregrefswgvregegsdgre intcount=0; while(run){//計(jì)算等待運(yùn)營(yíng)進(jìn)程個(gè)數(shù)count++; run=run->next; } run=head1;//還原運(yùn)營(yíng)鏈表 //建立一種映射表 char**Run_Process_Name=newchar*[count];//申請(qǐng)一種動(dòng)態(tài)二維表 for(inti=0;i<count;i++){//響應(yīng)二維空間申請(qǐng)完畢Run_Process_Name[i]=newchar[10]; strcpy(Run_Process_Name[i],run->ProcessName); run=run->next; } run=NULL;int*Run_Process_CpuNeed=newint[count]; //映射表建立完畢//計(jì)算各個(gè)進(jìn)程中所需cpu時(shí)間 ShowRunningProcess_CalculateCpuNeed(Run_Process_CpuNeed,count); Process*priorNode=NULL; //Process*tail=head; while(true){ //inttime11=wait->ArriveTime; if(wait&&NowTime>=wait->ArriveTime){ if(run==NULL){ run=wait; priorNode=run; }else{//連接到尾部Process*temp=run; while(temp->next!=priorNode){//尋找到前驅(qū)節(jié)點(diǎn) temp=temp->next; } temp->next=wait;//將結(jié)點(diǎn)連接上鏈表 priorNode=wait; //wait->next=run; } wait=wait->next;//釋放一種結(jié)點(diǎn) priorNode->next=run;//連接上頭部形成循環(huán)鏈表 } if(run){ run=run->next;//重新調(diào)度 cout<<NowTime<<"->"<<NowTime+RR<<"Process:"<<run->ProcessName<<"isRunning"<<endl; cout<<"cpu調(diào)度下一種運(yùn)營(yíng)進(jìn)程。"<<endl; NowTime+=RR; //根據(jù)上面建設(shè)映射 按名取出所需運(yùn)營(yíng)時(shí)間 intALLNeedCpu; for(inti=0;i<count;i++){if(strcmp(Run_Process_Name[i],run->ProcessName)==0) break; } ALLNeedCpu=Run_Process_CpuNeed[i];ALLNeedCpu-=RR;//減去本次運(yùn)營(yíng)時(shí)間 if(ALLNeedCpu>0){ Run_Process_CpuNeed[i]=ALLNeedCpu;//重新寫回到數(shù)組中保持一致性 }else{//此節(jié)點(diǎn)已經(jīng)做完了請(qǐng)直接釋放 if(run->next==run){ run=NULL; }else{ Process*k=run; while(k->next!=run){//尋找當(dāng)前運(yùn)營(yíng)節(jié)點(diǎn)前一種結(jié)點(diǎn) k=k->next; } k->next=k->next->next; run=k; } } }//endif(run) if(wait==NULL&&run==NULL)//沒(méi)有等待CPU進(jìn)程了和沒(méi)有正在運(yùn)營(yíng)進(jìn)程滿足退出規(guī)定->退出 break; NowTime++; }//while system("pause"); LinkCopy();////將受損鏈表修復(fù)}voidJOB::ShowRunningProcess(){ system("cls"); intNowTime=0; Process*run=head1;//暫時(shí)試用一下最后需要?dú)w還為NULL Process*wait=head1;//dsvrfgvregrefswgvregegsdgre intcount=0; while(run){//計(jì)算等待運(yùn)營(yíng)進(jìn)程個(gè)數(shù)count++; run=run->next; } run=head1;//還原運(yùn)營(yíng)鏈表 //建立一種映射表 char**Run_Process_Name=newchar*[count];//申請(qǐng)一種動(dòng)態(tài)二維表 for(inti=0;i<count;i++){//響應(yīng)二維空間申請(qǐng)完畢Run_Process_Name[i]=newchar[10]; strcpy(Run_Process_Name[i],run->ProcessName); run=run->next; } run=NULL;int*Run_Process_CpuNeed=newint[count]; //映射表建立完畢 ShowRunningProcess_CalculateCpuNeed(Run_Process_CpuNeed,count); Process*priorNode=NULL; while(true){ //inttime11=wait->ArriveTime; if(wait&&NowTime>=wait->ArriveTime){ if(run==NULL){ run=wait; priorNode=run; }else{//連接到尾部Process*temp=run; while(temp->next!=priorNode){//尋找到前驅(qū)節(jié)點(diǎn) temp=temp->next; } temp->next=wait;//將結(jié)點(diǎn)連接上鏈表 priorNode=wait; //wait->next=run; } wait=wait->next;//釋放一種結(jié)點(diǎn) priorNode->next=run;//連接上頭部形成循環(huán)鏈表 } if(run){ run=run->next;//重新調(diào)度 cout<<NowTime<<"->"<<NowTime+RR<<"Process:"<<run->ProcessName<<"isRunning"<<endl; cout<<"NeedRescourse:A"<<run->NeedRescourse[0]<<"B"<<run->NeedRescourse[1]<<"c"<<run->NeedRescourse[2]<<"isusing."<<endl; cout<<"cpu調(diào)度下一種運(yùn)營(yíng)進(jìn)程。"<<endl; NowTime+=RR; //根據(jù)上面建設(shè)映射 按名取出所需運(yùn)營(yíng)時(shí)間 intALLNeedCpu; for(inti=0;i<count;i++){if(strcmp(Run_Process_Name[i],run->ProcessName)==0) break; } ALLNeedCpu=Run_Process_CpuNeed[i];ALLNeedCpu-=RR;//減去本次運(yùn)營(yíng)時(shí)間 if(ALLNeedCpu>0){ Run_Process_CpuNeed[i]=ALLNeedCpu;//重新寫回到數(shù)組中保持一致性 }else{//此節(jié)點(diǎn)已經(jīng)做完了請(qǐng)直接釋放 if(run->next==run){ run=NULL; }else{ Process*k=run; while(k->next!=run){//尋找當(dāng)前運(yùn)營(yíng)節(jié)點(diǎn)前一種結(jié)點(diǎn) k=k->next; } k->next=k->next->next; run=k; } } }//endif(run) if(wait==NULL&&run==NULL)//沒(méi)有等待CPU進(jìn)程了和沒(méi)有正在運(yùn)營(yíng)進(jìn)程滿足退出規(guī)定->退出 break; NowTime++; }//while system("pause"); LinkCopy();////將受損鏈表修復(fù)}voidJOB::ShowRunningProcess_CalculateCpuNeed(int*Run_Process_CpuNeed,intcount){Process*temp=head1;for(inti=0;i<count;i++){intALLNeedCpu=temp->NeedCpuTime; if(temp->OpKind==IO){ if(temp->NeedTranDataNum%ONEDMANUM==0){ ALLNeedCpu+=(temp->NeedTranDataNum/ONEDMANUM)*(BEFOREDMA+AFTERDMA); }else{ ALLNeedCpu+=(temp->NeedTranDataNum/ONEDMANUM+1)*(BEFOREDMA+AFTERDMA); } }else{ ALLNeedCpu+=temp->OpCpus; } Run_Process_CpuNeed[i]=ALLNeedCpu; temp=temp->next; }}voidJOB::ShowProcessInfo(){system("cls"); Process*temp=head1; intcount=0; while(temp){ cout<<"------The"<<count+1<<"processinfo"<<endl; cout<<"Name:"<<temp->ProcessName<<'.'<<endl; cout<<"ArriveTime:"<<temp->ArriveTime<<'.'<<endl; cout<<"NeedCpuTime:"<<temp->NeedCpuTime<<'.'<<endl; cout<<"NeedMem:"<<temp->NeedMem<<'.'<<endl; cout<<"OpKind:"<<temp->OpKind<<'.'<<endl; cout<<"NeedRescourse:"<<"A:"<<temp->NeedRescourse[0]<<",B:"<<p->NeedRescourse[1] <<",C:"<<p->NeedRescourse[2]<<endl; temp=temp->next; cout<<'\n'; count++; } cout<<"enteranykeyreturnmain()."<<endl; getchar(); getchar();}voidJOB::DeedLock(){ system("cls");Process*temp=head1; intLocalA=0,LocalB=0,LocalC=0; while(temp){LocalA+=temp->NeedRescourse[0]; LocalB+=temp->NeedRescourse[1];LocalB+=temp->NeedRescourse[2]; temp=temp->next; } if(LocalA>A||LocalB>B||LocalC>C){cout<<"NeedRescourseisover!"<<endl;cout<<"Enter1toSeeNeedRescourse,elsetomain()!"<<endl; intn; cin>>n; if(n==1){DeedLock_LookNeedRescourse(); } }else{cout<<"YourJObisok!SystemNowissafe!"<<endl; } system("pause");}voidJOB::DeedLock_LookNeedRescourse(){Process*temp=head1; cout<<"\nNeedRescourse:ABC\n";while(temp){cout<<temp->ProcessName<<""<<temp->NeedRescourse[0]<<""<<temp->NeedRescourse[1]<<""<<temp->NeedRescourse[2]<<endl; temp=temp->next; } system("pause"); cout<<"AreyouwanttoKilloneProcesstoReleaseNeedRescourse.Y/N"<<endl; charoption;cin>>option; if(option=='Y'||option=='y'){DeedLock_KillProcess(); }}voidJOB::DeedLock_KillProcess(){Process*temp=head;cout<<"Enter1,2,....toKill1th,2th,....Process."<<endl;intn;cin>>n;intcount=1;while(count<n){count++; temp=temp->next;}if(count==1){head=head->next;}else{Process*temp2=head;n=1; while((n+1)<count){ n++; temp2=temp2->next; } temp2->next=temp->next;//刪除temp結(jié)點(diǎn)}LinkCopy();}voidJOB::LookCpu(){ system("cls");LookCpu_ShowRunningProcess();}voidJOB::LookMem(){intMem[128];intDiskMem[1024]; memset(Mem,0,128); memset(DiskMem,0,1024); DynReg=0; Process*temp=head1; while(temp&&DynReg<=128){ cout<<"MemeryFrom"<<DynReg<<"to"<<DynReg+temp->NeedMem-1<<"giveto"<<temp->ProcessName<<endl; DynReg+=temp->NeedMem; temp=temp->next; } cout<<"EnterAnyKeytoReturnMain()."<<endl; getchar(); getchar();}boolJOB::CheckMem(){//檢查虛擬存儲(chǔ)器與否可以接納 intsum=0; Process*temp=head; while(temp){ sum+=temp->NeedMem; } if(sum>=1024) returnfalse; else returntrue;}voidJOB::LookDiskMem(){ intsum=0; Process*temp=head; while(temp){ sum+=temp->NeedMem; temp=temp->next; } if(sum>1024){ cout<<"ThissystemDiskMemeryisout!\npleaseenter1tochangeyouprocessNeedMem\nelsesystemmayhavesomethingwrong"<<endl; intn; cout<<"Enter1toChangeMemerysizeelseSystemwillexit."<<endl; cin>>n; if(n==1){ LookDiskMem_Change(); }else{exit(0); } }else{ cout<<"\nJOBtotaluse:"<<sum<<"Memery!"<<endl; } cout<<"enteranykeyreturnmain()."<<endl; getchar(); getchar(); }voidJOB::LookDiskMem_Change(){ Process*temp=head; while(temp){ cout<<"Process:"<<temp->ProcessName<<"need"<<temp->NeedMem<<endl; temp=temp->next; } temp=head; while(temp){ charn; cout<<"Change"<<temp->ProcessName<<"NeedMem?Y/N(y/n)"<<endl; cin>>n; if(n=='Y'||n=='y'){ cout<<"EnteryouNewNeedMem:"<<endl; cin>>temp->NeedMem; }elseif(n=='N'||n=='n')
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 軟件安全設(shè)計(jì)評(píng)估報(bào)告范本
- 浙江省麗水市青田縣2023-2024學(xué)年五年級(jí)上學(xué)期英語(yǔ)期末試卷
- 石材固色劑知識(shí)培訓(xùn)課件
- 塑造五種心態(tài)培訓(xùn)課件4
- 年產(chǎn)6萬(wàn)噸飼用餅干粉和面包粉項(xiàng)目可行性研究報(bào)告寫作模板-申批備案
- 二零二五年度地產(chǎn)公司建筑工程合同風(fēng)險(xiǎn)評(píng)估與防控策略3篇
- 禮儀知識(shí)培訓(xùn)課件
- 二零二五年度辦公樓主體結(jié)構(gòu)施工與智慧安防系統(tǒng)合同3篇
- 中國(guó)大陸自閉癥干預(yù)方法研究綜述
- Unit 9 Can you come to my party Section A 1a~1c 說(shuō)課稿 -2024-2025學(xué)年人教版八年級(jí)英語(yǔ)上冊(cè)
- 口腔頜面外科學(xué) 09顳下頜關(guān)節(jié)疾病
- 臺(tái)達(dá)變頻器說(shuō)明書
- 2023年廣東羅浮山旅游集團(tuán)有限公司招聘筆試題庫(kù)及答案解析
- DB11-T1835-2021 給水排水管道工程施工技術(shù)規(guī)程高清最新版
- 解剖篇2-1內(nèi)臟系統(tǒng)消化呼吸生理學(xué)
- 《小學(xué)生錯(cuò)別字原因及對(duì)策研究(論文)》
- 北師大版七年級(jí)數(shù)學(xué)上冊(cè)教案(全冊(cè)完整版)教學(xué)設(shè)計(jì)含教學(xué)反思
- 智慧水庫(kù)平臺(tái)建設(shè)方案
- 系統(tǒng)性紅斑狼瘡-第九版內(nèi)科學(xué)
- 全統(tǒng)定額工程量計(jì)算規(guī)則1994
- 糧食平房倉(cāng)設(shè)計(jì)規(guī)范
評(píng)論
0/150
提交評(píng)論