




已閱讀5頁,還剩13頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
實 驗 報 告(2014 / 2015 學(xué)年 第 一 學(xué)期)課程名稱計算機操作系統(tǒng)實驗名稱虛擬存儲中頁面置換算法的模擬實現(xiàn)實驗時間2014年12月19日指導(dǎo)單位南京郵電大學(xué)指導(dǎo)教師崔衍學(xué)生姓名班級學(xué)號學(xué)院(系)物聯(lián)網(wǎng)院專 業(yè)網(wǎng)絡(luò)工程實 驗 報 告實驗名稱虛擬存儲中頁面置換算法的模擬實現(xiàn)指導(dǎo)教師崔衍實驗類型上機實驗實驗學(xué)時4實驗時間2014.12.19一、 實驗?zāi)康暮鸵竽康模和ㄟ^請求頁式存儲管理中頁面置換算法模擬設(shè)計,了解虛擬存儲技術(shù)的技術(shù)特點,掌握請求頁式存儲管理的頁面置換算法要求:(1)設(shè)計實現(xiàn)下面算法,并輸出下述各種算法的命中率。 先進(jìn)先出的算法(FIFO); 最近最少使用算法(LRR); 最佳淘汰算法(OPT)先淘汰最不常用的頁地址。(2)多次反復(fù)運行改進(jìn)后的程序,觀察并記錄運行結(jié)果,并分析原因。二、實驗環(huán)境(實驗設(shè)備)Vc+6.0二、 實驗原理及內(nèi)容實驗三#include #include#include#include#define Bsize 4typedef struct BLOCK/聲明一種新類型物理塊類型 int pagenum;/頁號 int accessed;/訪問字段,其值表示多久未被訪問BLOCK; int pc;/程序計數(shù)器,用來記錄指令的序號int n;/缺頁計數(shù)器,用來記錄缺頁的次數(shù) static int temp320;/用來存儲320條隨機數(shù)BLOCK blockBsize; /定義一大小為4的物理塊數(shù)組/*void init( ); /程序初始化函數(shù)int findExist(int curpage);/查找物理塊中是否有該頁面int findSpace( );/查找是否有空閑物理塊int findReplace( );/查找應(yīng)予置換的頁面void display ( );/顯示void suijishu( );/產(chǎn)生320條隨機數(shù),顯示并存儲到temp320void pagestring( );/顯示調(diào)用的頁面隊列void OPT( );/OPT算法void LRU( );/ LRU算法void FIFO( );/FIFO算法/*void init( ) for(int i=0;iBsize;i+) blocki.pagenum=-1; blocki.accessed=0; pc=n=0; /-int findExist(int curpage) for(int i=0; iBsize; i+) if(blocki.pagenum = curpage ) return i;/檢測到內(nèi)存中有該頁面,返回block中的位置 return -1;/-int findSpace( ) for(int i=0; iBsize; i+) if(blocki.pagenum = -1) return i;/找到空閑的block,返回block中的位置 return -1;/-int findReplace( ) int pos = 0; for(int i=0; iblockpos.accessed) pos = i;/找到應(yīng)予置換頁面,返回BLOCK中位置 return pos;/-void display( ) for(int i=0; iBsize; i+) if(blocki.pagenum != -1) printf( %02d,blocki.pagenum); coutpc; cout*按照要求產(chǎn)生的320個隨機數(shù):*endl; for(int i=0;i320;i+) tempi=pc; if(flag%2=0) pc=+pc%320; if(flag=1) pc=rand( )% (pc-1); if(flag=3) pc=pc+1+(rand( )%(320-(pc+1); flag=+flag%4; printf( %03d,tempi); if(i+1)%10=0) coutendl; /-void pagestring( ) for(int i=0;i320;i+) printf( %02d,tempi/10); if(i+1)%10=0) coutendl; /-void OPT( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace ( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else for(int k=0;kBsize;k+) for(int j=i;j320;j+) if(blockk.pagenum!= tempj/10) blockk.accessed = 1000; /將來不會用,設(shè)置為一個很大數(shù) else blockk.accessed = j; break; position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; cout缺頁次數(shù):nendl; cout缺頁率:(n/320.0)*100%endl;/- void LRU( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; else blockexist.accessed = -1;/恢復(fù)存在的并剛訪問過的BLOCK中頁面accessed為-1 for(int j=0; j4; j+) blockj.accessed+; cout缺頁次數(shù):nendl; cout缺頁率:(n/320.0)*100%endl;/-void FIFO( ) int exist,space,position ; int curpage; for(int i=0;i320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; blockposition.accessed-; for(int j=0; jBsize; j+) blockj.accessed+; cout缺頁次數(shù):nendl; cout缺頁率:(n/320.0)*100%endl;/*void main( ) int select; cout請輸入第一條指令號(0320):; suijishu( ); cout*對應(yīng)的調(diào)用頁面隊列*endl; pagestring( ); do cout*endl; cout-1:OPT 2:LRU 3:FIFO 4:退出-endl; cout*endl; coutselect; cout*endl; init( ); switch(select) case 1:cout最佳置換算法OPT:endl; cout*endl; OPT( ); break; case 2:cout最近最久未使用置換算法LRU:endl; cout*endl; LRU( ); break; case 3:cout先進(jìn)先出置換算法FIFO:endl; cout*endl; FIFO( ); break; default: ; while(select!=4);實驗結(jié)果: 實驗四Login用戶登錄bool chklogin(char *users, char *pwd)int i;for(i=0; itemp-filename;cintemp-content;if(recent-child=NULL)temp-parent=recent;temp-child=NULL;recent-child=temp;temp-prev=temp-next=NULL;cout文件建立成功!child;while(ttemp-next)ttemp=ttemp-next;if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0)printf(對不起,文件已存在!);return 1;ttemp-next=temp;temp-parent=NULL;temp-child=NULL;temp-prev=ttemp;temp-next=NULL;cout文件建立成功!endl;return 1;int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout .child=NULL)coutTotal: directors i files j child;while(temp)if(temp-isdir)cout filenameendl;i+;elsecout filenamenext;coutTotal: directors ifiles j filename;if(recent-child=NULL)cout文件不存在!child-filename,filename)=0)coutchild-contentchild;while(temp-next)if(strcmp(temp-next-filename,filename)=0)coutnext-contentendl;return 1;cout文件不存在!filename;if(recent-child=NULL)cout文件不存在!child-filename,filename)=0)recent-child-isopen=1;/設(shè)置文件標(biāo)記為打開cinrecent-child-content;recent-child-isopen=0;/設(shè)置文件標(biāo)記為關(guān)閉cout文件寫入成功!child;while(temp-next)if(strcmp(temp-next-filename,filename)=0)recent-child-isopen=1;/設(shè)置文件標(biāo)記為打開cintemp-next-content;recent-child-isopen=0;/設(shè)置文件標(biāo)記為關(guān)閉cout文件寫入成功!endl;return 1;cout文件不存在!filename;temp=new fnode;if(recent-child)temp=recent-child;while(temp-next & (strcmp(temp-filename,filename)!=0 | temp-isdir!=0)temp=temp-next;if(strcmp(temp-filename,filename)!=0)cout不存在該文件!endl;return 0;elsecout不存在該文件!parent=NULL)temp-prev-next=temp-next;if(temp-next)temp-next-prev=temp-prev;temp-prev=temp-next=NULL;elseif(temp-next)temp-next-parent=temp-parent;temp-parent-child=temp-next;delete temp;cout文件已刪除!temp-filename;if(recent-child=NULL)temp-parent=recent;temp-child=NULL;recent-child=temp;temp-prev=temp-next=NULL;elsettemp=recent-child;while(ttemp-next)ttemp=ttemp-next;if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1)printf(對不起,目錄已存在!);return 1;ttemp-next=temp;temp-parent=NULL;temp-child=NULL;temp-prev=ttemp;temp-next=NULL;return 1;切換目錄int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout .child=NULL)coutTotal: directors i files j child;while(temp)if(temp-isdir)cout filenameendl;i+;elsecout filenamenext;coutTotal: directors ifiles j endl;四、實驗小結(jié)(包括問題和解決方法、心得體會、意見與建議等)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 執(zhí)業(yè)醫(yī)師考試適應(yīng)力培養(yǎng)與提升試題及答案
- 中小學(xué)生品德教育
- 2025年內(nèi)容機構(gòu)行業(yè)發(fā)展研究報告
- 藥物相互作用類型及實例試題及答案
- 婦科健康宣教課件
- (小學(xué)語文資料)人教版五年級上冊語文期末考試卷16及參考答案
- 奧運開幕課件
- 畢業(yè)班家長會課件
- 執(zhí)業(yè)醫(yī)師考試經(jīng)驗學(xué)習(xí)與分享會試題及答案
- 毒品預(yù)防班會課件
- 2025年部編版新教材語文一年級下冊第七單元復(fù)習(xí)課教案
- 《低壓電工實操及考證》全套教學(xué)課件
- 個人閱兵申請書
- 頸椎病課件完整版
- 2025年國家藥監(jiān)局醫(yī)療器械技術(shù)審評檢查大灣區(qū)分中心事業(yè)編制人員招聘5人歷年高頻重點提升(共500題)附帶答案詳解
- 巡邏盤查培訓(xùn)課件
- GB/T 39733-2024再生鋼鐵原料
- 《工業(yè)機器人現(xiàn)場編程》課件-任務(wù)3.涂膠機器人工作站
- 程序設(shè)計高級應(yīng)用(Java程序設(shè)計)知到智慧樹章節(jié)測試課后答案2024年秋山東勞動職業(yè)技術(shù)學(xué)院
- 2025年教師資格考試高級中學(xué)學(xué)科知識與教學(xué)能力物理試題與參考答案
- 安徽工業(yè)大學(xué)《工程經(jīng)濟(jì)與項目管理》2022-2023學(xué)年第一學(xué)期期末試卷
評論
0/150
提交評論