基于多隊列反饋的進程調(diào)度_第1頁
基于多隊列反饋的進程調(diào)度_第2頁
基于多隊列反饋的進程調(diào)度_第3頁
基于多隊列反饋的進程調(diào)度_第4頁
基于多隊列反饋的進程調(diào)度_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上操作系統(tǒng)綜合實訓(xùn)項目設(shè)計文檔【大綱】(不用打印,提交電子稿即可!)一、 基本信息項目名稱:成人姓名、學(xué)號、完成日期項目名稱:基于時間片的多隊列反饋的進程管理系統(tǒng)完成日期:2017.5.24二、 實驗內(nèi)容與目的實驗內(nèi)容:編寫程序完成單處理器系統(tǒng)的進程調(diào)度,要求采用基于時間片多隊列反饋式調(diào)度策略調(diào)度策略。具體內(nèi)容:1.確定PCB內(nèi)容及其組織方式。2.要求模擬進程空閑(新)、就緒、運行、阻塞和完成5個狀態(tài)。3.實現(xiàn)進程創(chuàng)建、進程調(diào)度、進程阻塞、進程喚醒和進程撤銷5個原語。4.能夠模擬進程從生到滅的完整過程。實驗?zāi)康? 1.加深進程概念理解,明確進程與程序區(qū)別。2.理解操作系

2、統(tǒng)中進程的組織、創(chuàng)建和調(diào)度等方法。三、 主要設(shè)計思路和流程圖設(shè)計思路:1定義數(shù)據(jù)結(jié)構(gòu)2.設(shè)置隊列3.創(chuàng)建進程4.創(chuàng)建的進程進入就緒隊列5.多級反饋調(diào)度1.)在第一就緒隊列里的進程被調(diào)度運行,進程狀態(tài)由等待變?yōu)檫\行,設(shè)置時間片計數(shù)器,每次運行加1,時間片滿后,該進程出隊列,進入下一級別的就緒隊列。若是在最后一級別的隊列,則在該隊列中進行時間片輪轉(zhuǎn)調(diào)度2.)運行進程若是被阻塞的話,該進程出就緒隊列,進入阻塞隊列,狀態(tài)變?yōu)樽枞麘B(tài)3.)若是喚醒被阻塞進程,則阻塞進程根據(jù)其時間片計數(shù)器計入相應(yīng)的就緒隊列4.)撤銷進程,該進程直接出就緒隊列四、 主要數(shù)據(jù)結(jié)構(gòu)及其說明typedef struct Node

3、char name20; char state;/進程所處的狀態(tài),N新建,W等待,B阻塞,R運行,F(xiàn)結(jié)束int round;/時間片計數(shù)器 int time;/運行時間 struct Node *next;LinkQueueNode,*PCB;/定義PCBtypedef struct LinkQueueNode *front; LinkQueueNode *rear;LinkQueue;/定義隊列void initQueue(LinkQueue *Q)/隊列的初始化函數(shù)void Initializa()/初始化所有隊列void RunPrintf()/打印運行隊列void BlockPrint

4、f()/打印阻塞隊列void ReadyPrintf(LinkQueue q)/打印就緒隊列void putout()/輸出函數(shù)void EnterQueue(LinkQueue *Q,PCB *p)/進程插入隊列函數(shù)int DeleteQueue(LinkQueue *Q,PCB *p)/進程出隊列void TransferRun(LinkQueue *q1,LinkQueue *q2,PCB q)/進程出就緒隊列,入運行隊列void Transfer(LinkQueue *q1,LinkQueue *q2,PCB q)/進程喚醒或阻塞時隊列轉(zhuǎn)換的函數(shù)int MultiDiapatch()/

5、調(diào)度函數(shù),若此隊列運行的進程時間片滿,則進入下一級隊列int run()/模擬運行void block()/模擬阻塞void wake()/模擬喚醒int Createprocess(LinkQueue *Q)/進程的創(chuàng)建void meanu()/菜單函數(shù)五、 程序運行時的初值和運行結(jié)果六、 源程序并附上注釋【可是另一個源程序文件,在此應(yīng)說明該文件名】#include#include#include#includetypedef struct Node char name20; char state;/進程所處的狀態(tài),N新建,W等待,B阻塞,R運行,F(xiàn)結(jié)束int round;/時間片計數(shù)器 i

6、nt time;/運行時間 struct Node *next;LinkQueueNode,*PCB;/定義PCBtypedef struct LinkQueueNode *front; LinkQueueNode *rear;LinkQueue;int count=0;LinkQueue qRun,qBlock,qReady1,qReady2,qReady3,qReady4;/定義四個就緒隊列void initQueue(LinkQueue *Q)/隊列的初始化函數(shù) Q-front = (LinkQueueNode *)malloc(sizeof(LinkQueueNode); if(Q-f

7、ront!=NULL) Q-rear=Q-front; Q-front-next=NULL; void Initializa()/初始化所有隊列 initQueue(&qRun); initQueue(&qBlock);initQueue(&qReady1);initQueue(&qReady2);initQueue(&qReady3);initQueue(&qReady4);void RunPrintf()/打印運行隊列PCB p;printf(運行隊列:); p=qRun.front-next; while(p) printf(%st,p-name); p=p-next; p=qRun.f

8、ront-next; printf(n需要時間:); while(p) printf(%dt,p-time); p=p-next; printf(n進程狀態(tài):); p=qRun.front-next;while(p) printf(%ct,p-state); p=p-next; void BlockPrintf()/打印阻塞隊列PCB p; printf(nn阻塞隊列:); p=qBlock.front-next; while(p) printf(%st,p-name); p=p-next; printf(n需要時間:); p=qBlock.front-next;while(p) printf

9、(%dt,p-time); p=p-next; printf(n進程狀態(tài):); p=qBlock.front-next; while(p) printf(%ct,p-state); p=p-next; void ReadyPrintf(LinkQueue q)/打印就緒隊列PCB p; p=q.front-next; while(p) printf(%st,p-name); p=p-next; printf(n需要時間:); p=q.front-next;while(p) printf(%dt,p-time); p=p-next; printf(n進程狀態(tài):); p=q.front-next;

10、while(p) printf(%ct,p-state); p=p-next; void putout()/輸出函數(shù) PCB p; printf(*n); printf(*多級反饋調(diào)度*);printf(n*n); printf(說明:程序中四個就緒隊列的時間片分別為10,15,20,30);printf(n*n);printf(*菜單*n); printf(1.創(chuàng)建進程 2.阻塞進程 3.喚醒進程 4.撤銷進程 0.退出n); printf(*n); RunPrintf();BlockPrintf();printf(nn隊 列1:);ReadyPrintf(qReady1);printf(n

11、n隊 列2:);ReadyPrintf(qReady2);printf(nn隊 列3:);ReadyPrintf(qReady3);printf(nn隊 列4:);ReadyPrintf(qReady4);printf(n*n);void EnterQueue(LinkQueue *Q,PCB *p)/進程插入隊列函數(shù) (*p)-next=NULL; Q-rear-next=*p; Q-rear=*p;int DeleteQueue(LinkQueue *Q,PCB *p)/進程出隊列 if(Q-front=Q-rear) return 0; *p=Q-front-next; Q-front-

12、next=(*p)-next; if(Q-rear=*p) Q-rear=Q-front; return 1;void TransferRun(LinkQueue *q1,LinkQueue *q2,PCB q)/進程出就緒隊列,入運行隊列 DeleteQueue(q1,&q); q-state=R; EnterQueue(q2,&q);void runprocess()PCB p;int state1=0,state2=0,state3=0,state4=0;/state來判斷就緒隊列是否還有進程 if(qReady1.front!=qReady1.rear) TransferRun(&qR

13、eady1,&qRun,p);state1=1; elseif(qReady2.front!=qReady2.rear) TransferRun(&qReady2,&qRun,p);state2=1;elseif(qReady3.front!=qReady3.rear) TransferRun(&qReady3,&qRun,p);state3=1;elseif(qReady4.front!=qReady4.rear) TransferRun(&qReady4,&qRun,p);state4=1;if(state1=0&state2=0&state3=0&state4=0)printf(隊列中無

14、就緒進程!);elsesystem(cls);putout();void Transfer(LinkQueue *q1,LinkQueue *q2,PCB q)/進程喚醒或阻塞時隊列轉(zhuǎn)換的函數(shù) DeleteQueue(q1,&q); q-state=W; EnterQueue(q2,&q);int MultiDiapatch()/調(diào)度函數(shù),若此隊列運行的進程時間片滿,則進入下一級隊列 PCB p;qRun.front-next-time-;+count;if(qRun.front-next-time=0)DeleteQueue(&qRun,&p);free(p);runprocess();co

15、unt=0;elseif(qRun.front-next-round=count)if(count=10)qRun.front-next-round=15;Transfer(&qRun,&qReady2,p); if(count=15)qRun.front-next-round=20;Transfer(&qRun,&qReady3,p); if(count=20)qRun.front-next-round=30;Transfer(&qRun,&qReady4,p); if(count=30)qRun.front-next-round=30;Transfer(&qRun,&qReady4,p);

16、runprocess(); count=0;int run()/模擬運行 if(qRun.front=qRun.rear)/運行隊列空,則進行進程隊列轉(zhuǎn)換 runprocess();elseMultiDiapatch();system(cls);putout();void block()/模擬阻塞 PCB p;if(qRun.front!=qRun.rear)/運行隊列不為空,則運行進程出運行隊列,進入阻塞隊列 DeleteQueue(&qRun,&p);p-state=B;EnterQueue(&qBlock,&p);system(cls);putout();elsesystem(cls);

17、putout();printf(隊列中沒有進程在運行!);void wake()/模擬喚醒 PCB p;if(qBlock.front!=qBlock.rear)/根據(jù)時間片;來決定進入的就緒隊列 if(qBlock.front-next-round=10) Transfer(&qBlock,&qReady1,p);elseif(qBlock.front-next-round=15) Transfer(&qBlock,&qReady2,p);elseif(qBlock.front-next-round=20) Transfer(&qBlock,&qReady3,p);elseif(qBlock

18、.front-next-round=30) Transfer(&qBlock,&qReady4,p);elsesystem(cls);putout();printf(無等待進程!);void endprocess() PCB p;if(qRun.front=qRun.rear)printf(信息提示:無運行進程,請按Enter鍵運行進程!);elseDeleteQueue(&qRun,&p);free(p);system(cls);putout();printf(信息提示:選擇菜單功能或按Enter鍵執(zhí)行進程!);int CompareStr(LinkQueue q,char name20)/

19、比較字符串是否相同 PCB p; p=q.front-next; while(p)if(strcmp(p-name,name)=0)return 0;p=p-next;return 1;int CompareName(char name20)PCB p;p=qRun.front-next;int flag;flag=CompareStr(qRun,name);if(flag=0) return 0; flag=CompareStr(qBlock,name); if(flag=0) return 0; flag=CompareStr(qReady1,name); if(flag=0) retur

20、n 0; flag=CompareStr(qReady2,name); if(flag=0) return 0; flag=CompareStr(qReady3,name); if(flag=0) return 0; flag=CompareStr(qReady4,name); if(flag=0) return 0; return 1;int Createprocess(LinkQueue *Q)/進程的創(chuàng)建 PCB p;char n20;p=(PCB)malloc(sizeof(LinkQueueNode);printf(進程名: );fflush(stdin);scanf(%s,&n);

21、while(!CompareName(n)/判斷是否創(chuàng)建了已經(jīng)創(chuàng)建過的進程 printf(已經(jīng)有相同名字的進程存在);printf(n請重新輸入未創(chuàng)建過的進程:);fflush(stdin);scanf(%s,&n);strcpy(p-name,n);printf(所需時間: );fflush(stdin);scanf(%d,&(p-time);while(p-timetime);p-state=W; p-round=10; p-next=NULL; EnterQueue(Q,&p);void meanu()/菜單函數(shù) char c;printf(n選擇功能:);scanf(%c,&c);while(1) if(c=1) Createprocess(&qReady1); syste

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論