操作系統實驗九_第1頁
操作系統實驗九_第2頁
操作系統實驗九_第3頁
操作系統實驗九_第4頁
操作系統實驗九_第5頁
已閱讀5頁,還剩6頁未讀 繼續免費閱讀

下載本文檔

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

文檔簡介

1、精選優質文檔-傾情為你奉上學號E 專業計算機科學與技術 姓名施飛宇實驗日期2018/12/20 教師簽字 成績實驗報告【實驗名稱】最低松弛度優先調度算法【實驗目的】1. 學習最低松弛度算法思想。2. 用代碼實現改算法,解決最低松弛度優先調度問題。【實驗原理】最低松弛度優先(LLF)算法是根據任務緊急(或松弛)的程度,來確定任務的優先級。任務的緊急程度愈高,為該任務所賦予的優先級就愈高,使之優先執行。在實現該算法時要求系統中有一個按松弛度排序的實時任務就緒隊列,松弛度最低的任務排在隊列最前面,被優先調度。松弛度的計算方法如下: 任務的松弛度=必須完成的時間-其本身的運行時間-當前時間&

2、#160;其中其本身運行的時間指任務運行結束還需多少時間,如果任務已經運行了一部分,則: 任務松弛度=任務的處理時間-任務已經運行的時間 當前時間【實驗內容】數據結構:本實驗進程采用結構體來存儲線信息,采用結構體數組來存儲進程序列。進程結構定義如下:typedef structint start;/進程申請服務開始時間int over;/進程截止時間int survey1;/需要服務總時間int survey2;/已經服務時間int songchi;/松弛度int label;/等于0未被處理,等于1已經被處理完畢pcb;程序流程圖:程序代碼:%2018/12/20 篤行南樓 A20

3、2 E 施飛宇#include "iostream"#include <stdio.h>using namespace std;typedef structint start;/進程申請服務開始時間int over;/進程截止時間int survey1;/需要服務總時間int survey2;/已經服務時間int songchi;/松弛度int label;/等于0未被處理,等于1已經被處理完畢pcb;void pcb_A(pcb * A,int n)/A進程創建函數 int i; for(i=0;i<n+1;i+) Ai.start=i*20; Ai.s

4、urvey2=0; Ai.label=0; Ai.songchi=10; Ai.survey1=10; Ai.over=Ai.start+20; if(i!=n) cout<<"A"<<i+1<<"到達時間"<<Ai.start<<" 截止時間"<<Ai.over<<endl; void pcb_B(pcb * B,int n)/B進程創建函數 int i; for(i=0;i<n+1;i+) Bi.start=i*50; Bi.survey2=

5、0; Bi.label=0; Bi.songchi=25; Bi.survey1=25; Bi.over=Bi.start+50; if(i!=n) cout<<"B"<<i+1<<"到達時間"<<Bi.start<<" 截止時間"<<Bi.over<<endl; int test(pcb *X,int n,int time) int i,j; for(i=0;i<n;i+) if(Xi.label=0&&Xi.start<

6、=time) Xi.songchi=Xi.over-(Xi.survey1-Xi.survey2)-time; return i; return -1;void run_AB(pcb *A,int n1,pcb *B,int n2) int time; int ai,bi,ka,kb; int max_time; int AB=1; int label=0; if(n1*20>=n2*50) max_time=n1*20; else max_time=n2*50; cout<<"時間 "<<" A"<<"

7、;截止時間 "<<" 服務時間 "<<" 松弛度 "<<"B 截止時間 "<<" 服務時間 "<<" 松弛度 "<<endl; cout<<"0"<<" A"<<"1"<<" "<<A0.over<<" "<<A0.survey2&l

8、t;<" "<<A0.songchi<<" B"<<"1"<<" "<<B0.over<<" "<<B0.survey2<<" "<<B0.songchi<<endl; for(time=0;time<=max_time;time=time + 1) ka = test(A,n1,time); if(ka = -1) ai=ai+1; else

9、ai=ka; / cout<<"A"<<ai+1<<" "<<Aai.songchi<<endl; kb=test(B,n2,time); if(kb=-1) bi=bi+1; else bi=kb; / cout<<"B"<<bi+1<<" "<<Bbi.songchi<<endl; if(Bbi.songchi=0|ka=-1|label=1) AB=0;label=0; if(Aai.son

10、gchi=0|kb=-1|label=2) AB=1;label=0; if(AB=1&&ai<n1) if(Aai.survey1=(+Aai.survey2) cout<<time+1<<" A"<<ai+1<<" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1

11、<<" "<<Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<<endl; cout<<time+1<<" A"<<ai+1<<"進程結束"<<endl; Aai.label=1; label=1; else if(time+1)%5=0) cout<<time+1<<"

12、 A"<<ai+1<<" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1<<" "<<Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<

13、<endl; if(AB=0&&bi<n2) if(Bbi.survey1=(+Bbi.survey2) cout<<time+1<<" A"<<ai+1<<" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1<<" "<&

14、lt;Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<<endl; cout<<time+1<<" B"<<bi+1<<"進程結束"<<endl; Bbi.label=1; label=2; else if(time+1)%5=0) cout<<time+1<<" A"<<ai+1<&l

15、t;" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1<<" "<<Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<<endl; if(kb=-1) bi=bi-1; if(ka=-1) ai=ai-1; int main() int n1,n2; pcb A10,B10; cout<<"輸入A進程個數"<<

溫馨提示

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

評論

0/150

提交評論