實驗報告(操作系統).doc_第1頁
實驗報告(操作系統).doc_第2頁
實驗報告(操作系統).doc_第3頁
實驗報告(操作系統).doc_第4頁
實驗報告(操作系統).doc_第5頁
已閱讀5頁,還剩1頁未讀, 繼續免費閱讀

下載本文檔

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

文檔簡介

計算機學院綜合性、設計性實驗報告專業:計算機科學與技術 年級/班級:2013級一 班 20152016學年第一學期課程名稱計算機操作系統指導教師本組成員學號姓名實驗地點計科樓216實驗時間2015/12/6項目名稱進程調度實驗類型綜合性/設計性一、實驗目的:通過動態優先權調度算法和時間片輪轉調度算法的模擬加深進程概念和進程調度過程的理解。二、實驗儀器或設備:計算機一臺三、總體設計 整個程序可由主程序和如下7個過程組成:(1)在優先數算法中,將尚未完成的PCB按優先數順序插入到就緒隊列中;(2)在時間片輪轉算法中,將執行了一個時間片單位(為2),但尚未完成的進 程的PCB,插到就緒隊列的隊尾;(3)調度就緒隊列的第一個進程投入運行;(4)顯示每執行一次后所有進程的狀態及有關信息。(5)創建新進程,并將它的PCB插入就緒隊列;(6)按優先數算法調度進程;(7)按時間片輪轉法調度進程。四、實驗步驟#include #include #include typedef struct node char name20; int prio; /*進程的優先級*/int round; /*分配CPU的時間片*/ int cputime; /*CPU執行時間*/ int needtime; /*進程執行所需要的時間*/ char state; /*W:就緒態,R:執行態,F:完成態*/ int count; struct node *next;PCB; PCB *ready=NULL,*run=NULL,*finish=NULL;/*就緒隊列、執行隊列完成隊列*/ int num; void GetFirst();/*緒隊列取第一個節點*/ void Output();void InsertFinish(PCB *in);/*時間片隊列*/ void PrioCreate();/*優先級輸入*/void InsertPrio(PCB *in);/*創建優先級隊列*/void Priority();/*按照優先級調度*/void TimeCreate();/*時間片輸入*/ void InsertTime(PCB *in);/*時間片隊列*/void RoundRun();/*時間片輪轉調度*/ int main() char chose; printf(please input total process number:n); scanf(%d,&num); getchar(); printf(please input method:(P/R)n); scanf(%c,&chose); switch(chose) case P: case p: PrioCreate(); Priority(); break; case R: case r: TimeCreate(); RoundRun(); break; default:break; Output(); return 0; void GetFirst() run=ready; if(ready!=NULL) run-state=R; ready=ready-next; run-next=NULL; void Output() PCB *p; p=ready; printf(nametprioritytroundtcputimetneedtimetstatetcountn); while(p!=NULL) printf(%st%dtt%dt%dt%dtt%ct%dn,p-name,p-prio,p-round,p-cputime,p-needtime,p-state,p-count); p=p-next; p=finish; while(p!=NULL) printf(%st%dtt%dt%dt%dtt%ct%dn,p-name,p-prio,p-round,p-cputime,p-needtime,p-state,p-count); p=p-next; p=run; while(p!=NULL) printf(%st%dtt%dt%dt%dtt%ct%dn,p-name,p-prio,p-round,p-cputime,p-needtime,p-state,p-count); p=p-next; void InsertPrio(PCB *in)/*創建優先級隊列,優先數越小,優先級越低*/ PCB *fst,*nxt; fst=nxt=ready; if(ready=NULL) in-next=ready; ready=in; else/*查到合適的位置進行插入*/ if(in-prio=fst-prio)/*比第一個還要大,則插入到隊頭*/ in-next=ready; ready=in; else while(fst-next!=NULL)/*移動指針查找第一個別它小的元素的位置進行插入*/ nxt=fst; fst=fst-next; if(fst-next=NULL)/*已搜索到隊尾優先級數最小,插到隊尾*/ in-next=fst-next; fst-next=in; else/*插入到隊列中*/ nxt=in; in-next=fst; void InsertTime(PCB *in)/*將進程插到就緒隊列尾部*/ PCB *fst; fst=ready; if(ready=NULL) in-next=ready; ready=in; else while(fst-next!=NULL) fst=fst-next; in-next=fst-next; fst-next=in; void InsertFinish(PCB*in)/*將進程插入到完成隊列尾部*/ PCB *fst; fst=finish; if(finish=NULL) in-next=finish; finish=in; else while(fst-next!=NULL) fst=fst-next; in-next=fst-next; fst-next=in; void PrioCreate()/*優先級調度輸入*/ PCB *tmp; int i; printf(input name and needtime:n); for(i=0;iname); getchar(); scanf(%d,&(tmp-needtime); tmp-cputime=0; tmp-state=W; tmp-prio=50-tmp-needtime;/*需時越多,優先級越低*/ tmp-round=0; tmp-count=0; InsertPrio(tmp);/*按照優先級從高到低,插入到就緒隊列*/ void TimeCreate() PCB *tmp; int i; printf(please input name and needtime:n); for(i=0;iname); getchar(); scanf(%d,&(tmp-needtime); tmp-cputime=0; tmp-state=W; tmp-prio=0; tmp-round=2;/*每個進程所分配的時間片是2*/ tmp-count=0; InsertTime(tmp); void Priority()/*按優先級調度,每次執行一個時間片*/ int flag=1; GetFirst(); while(run!=NULL) Output(); /*輸出每次調度過程中狀態*/ while(flag) run-prio-=3;run-cputime+; run-needtime-; if(run-needtime=0) /*進程執行完畢,狀態置為F,插入到完成隊列*/ run-state=F; run-count+;/*進程執行的次數加1*/ InsertFinish(run); flag=0; else /*將進程狀態置為W,入就緒隊列*/ run-state=W; run-count+; InsertTime(run); flag=0; flag=1; GetFirst(); /*繼續取就緒隊列進程入執行隊列*/ void RoundRun() /*時間片輪轉調度算法*/ int flag=1; GetFirst(); while(run!=NULL) Output(); while(flag) run-count+; run-cputime+; run-needtime-; if(run-needtime=0) run-state=F; InsertFinish(run); flag=0; else if(run-count=run-round) /*時間片用完*/ run-state=W; run-count=0; /*計數器清零,為下次做準備*/ InsertTime(run); flag=0; flag=1; GetFirst(); 五、結果分析與總結總結:從本實驗要求用高級語言編寫模擬進程調度程序,加深理解了有關進程控制快、進程隊列等概念,并體會和了解優先數算法和時間片輪轉算法的

溫馨提示

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

評論

0/150

提交評論