




已閱讀5頁(yè),還剩13頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
實(shí) 驗(yàn) 報(bào) 告(2014 / 2015 學(xué)年 第 一 學(xué)期)課程名稱(chēng)計(jì)算機(jī)操作系統(tǒng)實(shí)驗(yàn)名稱(chēng)虛擬存儲(chǔ)中頁(yè)面置換算法的模擬實(shí)現(xiàn)實(shí)驗(yàn)時(shí)間2014年12月19日指導(dǎo)單位南京郵電大學(xué)指導(dǎo)教師崔衍學(xué)生姓名班級(jí)學(xué)號(hào)學(xué)院(系)物聯(lián)網(wǎng)院專(zhuān) 業(yè)網(wǎng)絡(luò)工程實(shí) 驗(yàn) 報(bào) 告實(shí)驗(yàn)名稱(chēng)虛擬存儲(chǔ)中頁(yè)面置換算法的模擬實(shí)現(xiàn)指導(dǎo)教師崔衍實(shí)驗(yàn)類(lèi)型上機(jī)實(shí)驗(yàn)實(shí)驗(yàn)學(xué)時(shí)4實(shí)驗(yàn)時(shí)間2014.12.19一、 實(shí)驗(yàn)?zāi)康暮鸵竽康模和ㄟ^(guò)請(qǐng)求頁(yè)式存儲(chǔ)管理中頁(yè)面置換算法模擬設(shè)計(jì),了解虛擬存儲(chǔ)技術(shù)的技術(shù)特點(diǎn),掌握請(qǐng)求頁(yè)式存儲(chǔ)管理的頁(yè)面置換算法要求:(1)設(shè)計(jì)實(shí)現(xiàn)下面算法,并輸出下述各種算法的命中率。 先進(jìn)先出的算法(FIFO); 最近最少使用算法(LRR); 最佳淘汰算法(OPT)先淘汰最不常用的頁(yè)地址。(2)多次反復(fù)運(yùn)行改進(jìn)后的程序,觀(guān)察并記錄運(yùn)行結(jié)果,并分析原因。二、實(shí)驗(yàn)環(huán)境(實(shí)驗(yàn)設(shè)備)Vc+6.0二、 實(shí)驗(yàn)原理及內(nèi)容實(shí)驗(yàn)三#include #include#include#include#define Bsize 4typedef struct BLOCK/聲明一種新類(lèi)型物理塊類(lèi)型 int pagenum;/頁(yè)號(hào) int accessed;/訪(fǎng)問(wèn)字段,其值表示多久未被訪(fǎng)問(wèn)BLOCK; int pc;/程序計(jì)數(shù)器,用來(lái)記錄指令的序號(hào)int n;/缺頁(yè)計(jì)數(shù)器,用來(lái)記錄缺頁(yè)的次數(shù) static int temp320;/用來(lái)存儲(chǔ)320條隨機(jī)數(shù)BLOCK blockBsize; /定義一大小為4的物理塊數(shù)組/*void init( ); /程序初始化函數(shù)int findExist(int curpage);/查找物理塊中是否有該頁(yè)面int findSpace( );/查找是否有空閑物理塊int findReplace( );/查找應(yīng)予置換的頁(yè)面void display ( );/顯示void suijishu( );/產(chǎn)生320條隨機(jī)數(shù),顯示并存儲(chǔ)到temp320void pagestring( );/顯示調(diào)用的頁(yè)面隊(duì)列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;/檢測(cè)到內(nèi)存中有該頁(yè)面,返回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)予置換頁(yè)面,返回BLOCK中位置 return pos;/-void display( ) for(int i=0; iBsize; i+) if(blocki.pagenum != -1) printf( %02d,blocki.pagenum); coutpc; cout*按照要求產(chǎn)生的320個(gè)隨機(jī)數(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; /將來(lái)不會(huì)用,設(shè)置為一個(gè)很大數(shù) else blockk.accessed = j; break; position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; cout缺頁(yè)次數(shù):nendl; cout缺頁(yè)率:(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ù)存在的并剛訪(fǎng)問(wèn)過(guò)的BLOCK中頁(yè)面accessed為-1 for(int j=0; j4; j+) blockj.accessed+; cout缺頁(yè)次數(shù):nendl; cout缺頁(yè)率:(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缺頁(yè)次數(shù):nendl; cout缺頁(yè)率:(n/320.0)*100%endl;/*void main( ) int select; cout請(qǐng)輸入第一條指令號(hào)(0320):; suijishu( ); cout*對(duì)應(yīng)的調(diào)用頁(yè)面隊(duì)列*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);實(shí)驗(yàn)結(jié)果: 實(shí)驗(yàn)四Login用戶(hù)登錄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(對(duì)不起,文件已存在!);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)記為打開(kāi)cinrecent-child-content;recent-child-isopen=0;/設(shè)置文件標(biāo)記為關(guān)閉cout文件寫(xiě)入成功!child;while(temp-next)if(strcmp(temp-next-filename,filename)=0)recent-child-isopen=1;/設(shè)置文件標(biāo)記為打開(kāi)cintemp-next-content;recent-child-isopen=0;/設(shè)置文件標(biāo)記為關(guān)閉cout文件寫(xiě)入成功!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(對(duì)不起,目錄已存在!);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;四、實(shí)驗(yàn)小結(jié)(包括問(wèn)題和解決方法、心得體會(huì)、意見(jiàn)與建議等)
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 八年級(jí)歷史備課組計(jì)劃
- 元宵節(jié)猜燈謎活動(dòng)總結(jié)
- 云南省龍陵一中2025年物理高二下期末綜合測(cè)試模擬試題含解析
- 企業(yè)第一季度營(yíng)銷(xiāo)工作計(jì)劃
- 地?zé)岚l(fā)電系統(tǒng)的智能運(yùn)維與數(shù)字化轉(zhuǎn)型研究-洞察及研究
- 分析生成式人工智能對(duì)新聞工作者能力需求的影響及其應(yīng)對(duì)策略
- 拇趾骨折的健康教育
- 牛肉解凍效果及蛋白氧化影響
- 前列腺出血護(hù)理課件
- 石油行業(yè)鉆井安全生產(chǎn)標(biāo)準(zhǔn)的制定與實(shí)施
- 05-衣之鏢-輔行訣湯液經(jīng)法用藥圖釋義
- LS/T 3240-2012湯圓用水磨白糯米粉
- GB/T 15298-1994電子設(shè)備用電位器第一部分:總規(guī)范
- 泥水平衡盾構(gòu)簡(jiǎn)介課件
- 新教科版六下科學(xué)4-6《生命體中的化學(xué)變化》教案
- 2023高中學(xué)業(yè)水平合格性考試歷史重點(diǎn)知識(shí)點(diǎn)歸納總結(jié)(復(fù)習(xí)必背)
- 自然指數(shù)NatureIndex(NI)收錄的68種自然科學(xué)類(lèi)期刊
- 手術(shù)報(bào)告審批單
- 《專(zhuān)業(yè)導(dǎo)論光電信息科學(xué)與工程》教學(xué)大綱
- 廣東省湛江市各縣區(qū)鄉(xiāng)鎮(zhèn)行政村村莊村名明細(xì)
- 少兒美術(shù)國(guó)畫(huà)- 少兒希望 《紫藤課件》
評(píng)論
0/150
提交評(píng)論