操作系統(tǒng)試驗報告_第1頁
操作系統(tǒng)試驗報告_第2頁
操作系統(tǒng)試驗報告_第3頁
操作系統(tǒng)試驗報告_第4頁
操作系統(tǒng)試驗報告_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

實驗二進程調(diào)度1.目的和要求通過這次實驗,理解進程調(diào)度的過程,進一步掌握進程狀態(tài)的轉(zhuǎn)變、進程調(diào)度的策略,進一步體會多道程序并發(fā)執(zhí)行的特點,并分析具體的調(diào)度算法的特點,掌握對系統(tǒng)性能的評價方法。.實驗內(nèi)容編寫程序模擬實現(xiàn)進程的輪轉(zhuǎn)法調(diào)度過程,模擬程序只對PCB進行相應的調(diào)度模擬操作,不需要實際程序。假設初始狀態(tài)為:有n個進程處于就緒狀態(tài),有m個進程處于阻塞狀態(tài)。采用輪轉(zhuǎn)法進程調(diào)度算法進行調(diào)度(調(diào)度過程中,假設處于執(zhí)行狀態(tài)的進程不會阻塞),且每過t個時間片系統(tǒng)釋放資源,喚醒處于阻塞隊列隊首的進程。程序要求如下:1) 輸出系統(tǒng)中進程的調(diào)度次序;2) 計算CPU利用率。.實驗環(huán)境Windows操作系統(tǒng)、VC++6.0C語言4.實驗要求:1) 上機前認真使用C語言編寫好程序,采用VisualC++6.0作為編譯環(huán)境;2) 上機時獨立調(diào)試程序3) 根據(jù)具體實驗要求,填寫好實驗報告(包括目的和要求、實驗內(nèi)容、實驗環(huán)境、設計思想、源程序、實例運行結(jié)果、總結(jié))。4) 測試用數(shù)據(jù):n=2m=3t=5dispath()算法流程圖:use_cpu=0x=0unuse_cpu=0/*use_cpu中記錄CPU運行時間源程序:#include<stdio.h>#include<stdlib.h>structPCB_type{intpid; 〃進程名intstate; 〃進程狀態(tài)//2--表示”執(zhí)行”狀態(tài)//1--表示”就緒”狀態(tài)//0--表示”阻塞”狀態(tài)intcpu_time;〃運行需要的CPU時間(需運行的時間片個數(shù))};structQueueNode{structPCB_typePCB;structQueueNode*next;};//ready隊列隊首指針//ready隊列隊首指針//ready隊列隊尾指針//blocked隊列隊首指針//blocked隊列隊尾指針*ready_tail=NULL,*block_head=NULL,*block_tail=NULL;intuse_cpu,unuse_cpu;voidstart_state()〃讀入假設的數(shù)據(jù),設置系統(tǒng)初始狀態(tài){intn,m;inti;structQueueNode*p,*q;printf("輸入就緒節(jié)點個數(shù)n:");scanf("%d”,&n);printf("輸入阻塞節(jié)點個數(shù)m:");scanf("%d”,&m);p=(structQueueNode*)malloc(sizeof(structQueueNode));p->next=NULL;ready_head=ready_tail=p;for(i=0;i<n;i++){p=(structQueueNode*)malloc(sizeof(structQueueNode));p->next=NULL;p->PCB.state=1;printf("輸入就緒進程%d的pid和cpu_time:",i+1);scanf("%d%d”,&p->PCB.pid,&p->PCB.cpu_time);ready_tail->next=p;ready_tail=p;}q=(structQueueNode*)malloc(sizeof(structQueueNode));q->next=NULL;block_head=block_tail=q;for(i=0;i<m;i++){q=(structQueueNode*)malloc(sizeof(structQueueNode));q->next=NULL;q->PCB.state=0;printf("輸入阻塞進程%d的pid和cpu_time:",i+1);scanf("%d%d”,&q->PCB.pid,&q->PCB.cpu_time);block_tail->next=q;block_tail=q;}printf("\n處于就緒狀態(tài)的進程有:\n");p=ready_head->next;i=1;while(p){printf("進程%d的pid和state和cpu_time:%5d%5d%5d\n”,i,p->PCB.pid,p->PCB.state,p->PCB.cpu_time);p=p->next;i++;}}voiddispath() //模擬調(diào)度{intx=0,t;use_cpu=0;unuse_cpu=0;printf('輸入t:");scanf("%d”,&t);printf("開始調(diào)度\n");while(ready_head!=ready_tail||block_head!=block_tail){structQueueNode*p,*q;if(ready_head!=ready_tail)p=ready_head->next;ready_head->next=p->next;p->next=NULL;if(ready_head->next==NULL){ready_tail=ready_head;}p->PCB.state=2;printf("進程%d調(diào)度\t",p->PCB.pid);use_cpu++;x++;p->PCB.cpu_time--;if(p->PCB.cpu_time){ready_tail->next=p;ready_tail=p;}else{printf("進程%d完成\t",p->PCB.pid);free(p);}}else{unuse_cpu++;x++;printf("空閑一個時間片\『);}if(x==t&&block_head!=block_tail){q=block_head->next;block_head->next=q->next;q->next=NULL;if(block_head->next==NULL){block_tail=block_head;}ready_tail->next=q;ready_tail=q;x=0;

}voidcalculate()〃計算CPU利用率{printf("\ncpu的利用率%.2f\n",(float)use_cpu/(use_cpu+unuse_cpu));}voidmain()(start_state();dispath();calculate();}111片片一個時間片£就緒狀態(tài)的進程有二pid^Ustatecpu_time:呈2的pid^Ustate^Qcpu_time:^:5_time:1_time:2_time:111片片一個時間片£就緒狀態(tài)的進程有二pid^Ustatecpu_time:呈2的pid^Ustate^Qcpu_time:^:5_time:1_time:2_time:3_time:4_time:5145.運行結(jié)果片可.1 成^^度度23-45SSS進進空進進度度度成成兀13445SS11S1S1S1S1S.卜_1.■.?_1.■.?_1.■.?_1.■.?_1.■uuuuUppppPCCCCCnnnnn23-木豐木豐木■■■■nniiiii蜘數(shù)^pftpftpftpftp.ru12123點點曲進進進進.*■W04-I-7V.ILcpu的利用率@-79Pressanykeyt1成度度度一1345

H

進進進進7.實驗小結(jié)通過模擬進程調(diào)度的實驗,熟悉了進程調(diào)度算法,對進程調(diào)度的原理有了進步的認識,鞏固了理論知識,同時復習了C語言的知識。實驗三可變分區(qū)存儲管理1.目的和要求通過這次實驗,加深對內(nèi)存管理的認識,進一步掌握內(nèi)存的分配、回收算法的思想。.實驗內(nèi)容編寫程序模擬實現(xiàn)內(nèi)存的動態(tài)分區(qū)法存儲管理。內(nèi)存空閑區(qū)使用自由鏈管理,采用最壞適應算法從自由鏈中尋找空閑區(qū)進行分配,內(nèi)存回收時假定不做與相鄰空閑區(qū)的合并。假定系統(tǒng)的內(nèi)存共640K,初始狀態(tài)為操作系統(tǒng)本身占用64K。在t1時間之后,有作業(yè)A、B、C、D分別請求8K、16K、64K、124K的內(nèi)存空間;在t2時間之后,作業(yè)C完成;在t3時間之后,作業(yè)E請求50K的內(nèi)存空間;在t4時間之后,作業(yè)D完成。要求編程序分別輸出t1、t2、t3、t4時刻內(nèi)存的空閑區(qū)的狀態(tài)。.實驗環(huán)境Windows操作系統(tǒng)、VC++6.0C語言4.實驗要求:1) 上機前認真使用C語言編寫好程序,采用VisualC++6.0作為編譯環(huán)境;2) 上機時獨立調(diào)試程序3) 根據(jù)具體實驗要求,填寫好實驗報告(包括目的和要求、實驗內(nèi)容、實驗環(huán)境、設計思想、源程序、實例運行結(jié)果、總結(jié))。

requireMemo(charname,intrequire)流程圖如下:requireMemo(charname,intrequire)流程圖如下:endfreeMemo(charname)流程圖如下:if(p==busy_tail)busy_tail=q;printf("%cisnotexist”,name)q->next=p->next;len=p->len;address=p->address;free(p) 】ri是 -end: 十是

w=(structfreelink*)malloc(..?);w->len=len;w->address=address;1Fend源程序:#include<stdio.h>#include<stdlib.h>structfreelinkNode(intlen;intaddress;structfreelinkNode*next;};structbusylinkNode(charname;intlen;intaddress;structbusylinkNode*next;};structfreelinkNode*free_head=NULL;//自由鏈隊列(帶頭結(jié)點)隊首指針structbusylinkNode*busy_head=NULL;〃占用區(qū)隊列隊(帶頭結(jié)點)首指針structbusylinkNode*busy_tail=NULL;〃占用區(qū)隊列隊尾指針voidstart(void)/*設置系統(tǒng)初始狀態(tài)*/{structfreelinkNode*p;structbusylinkNode*q;free_head=(structfreelinkNode*)malloc(sizeof(structfreelinkNode));free_head->next=NULL;//創(chuàng)建自由鏈頭結(jié)點busy_head=busy_tail=(structbusylinkNode*)malloc(sizeof(structbusylinkNode));busy_head->next=NULL;//創(chuàng)建占用鏈頭結(jié)點p=(structfreelinkNode*)malloc(sizeof(structfreelinkNode));p->address=64;p->len=640-64;//OS占用了64Kp->next=NULL;free_head->next=p;q=(structbusylinkNode*)malloc(sizeof(structbusylinkNode));q->name='S';/*S表示操作系統(tǒng)占用*/q->len=64;q->address=0;q->next=NULL;busy_head->next=q;busy_tail=q;}voidrequireMemo(charname,intrequire)/*模擬內(nèi)存分配*/{freelinkNode*w,*u,*v;busylinkNode*p;if(free_head->next->len>=require){p=(structbusylinkNode*)malloc(sizeof(structbusylinkNode));p->name=name;p->address=free_head->next->address;p->len=require;p->next=NULL;busy_tail->next=p;busy_tail=p;}elseprintf("Can'tallocate");w=free_head->next;free_head->next=w->next;if(w->len==require){free(w);}else{w->address=w->address+require;w->len=w->len-require;}u=free_head;v=free_head->next;while((v!=NULL)&&(v->len>w->len)){u=v;v=v->next;}u->next=w;w->next=v;}voidfreeMemo(charname)/*模擬內(nèi)存回收*/{intlen;intaddress;busylinkNode*q,*p;freelinkNode*w,*u,*v;q=busy_head;p=busy_head->next;while((p!=NULL)&&(p->name!=name)){q=p;p=p->next;}if(p==NULL){printf("%cisnotexist",name);else{if(p==busy_tail){busy_tail=q;}else{q->next=p->next;len=p->len;address=p->address;free(p);w=(structfreelinkNode*)malloc(sizeof(structfreelinkNode));w->len=len;w->address=address;u=free_head;v=free_head->next;while((v!=NULL)&&(v->len>len)){u=v;v=v->next;}u->next=w;w->next=v;}}}voidpast(inttime)/*模擬系統(tǒng)過了time時間*/{printf("過了時間%d后:\n”,time);}voidprintlink()/*輸出內(nèi)存空閑情況(自由鏈的結(jié)點)*/{freelinkNode*p;printf("內(nèi)存的空閑情況為:\n");p=(structfreelinkNode*)malloc(sizeof(structfreelinkNode));p=free_head->next;while(p!=NULL){ printf("內(nèi)存的起始地址和內(nèi)存的大?。?d\t%5d:\n”,p->address,p->len);p=p->next;}}voidmain(){intt1=1,t2=2,t3=3,t4=4;start();

past(tl);requireMemo('A',8);requireMemo('B',16);requireMemo('C',64);requireMemo('D',124);printlink();past(t2);f

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論