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

下載本文檔

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

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上學(xué)號E 專業(yè)計算機科學(xué)與技術(shù) 姓名施飛宇實驗日期2018/10/25 教師簽字 成績實驗報告【實驗名稱】 進程調(diào)度【實驗?zāi)康摹快柟毯图由钐幚頇C調(diào)度的概念。設(shè)計調(diào)度算法,模擬實現(xiàn)處理機的調(diào)度【實驗原理】先來先服務(wù)(FCFS)調(diào)度算法FCFS是最簡單的調(diào)度算法,該算法既可用于作業(yè)調(diào)度,也可用于進程調(diào)度。 當在作業(yè)調(diào)度中采用該算法時,系統(tǒng)將按照作業(yè)到達的先后次序來進行調(diào)度,或者說它是優(yōu)先考慮在系統(tǒng)中等待時間最長的作業(yè),而不管該作業(yè)所需執(zhí)行時間的長短,從后備作業(yè)隊列中選擇幾個最先進入該隊列的作業(yè),將它們調(diào)入內(nèi)存,為它們分配資源和創(chuàng)建進程,然后把它放入就緒隊列?!緦嶒瀮?nèi)容】本次

2、實驗進程的數(shù)據(jù)結(jié)構(gòu)如下:typedef struct pcbchar pnameN;/進程名int runtime;/運行時間int arrivetime;/到達時間int starttime;/開始運行時間 float avgtime;/帶權(quán)周轉(zhuǎn)時間char state;/進程狀態(tài) struct pcb *next;/鏈表指針PCB;1. 設(shè)計先來先服務(wù)調(diào)度算法FCFS測試數(shù)據(jù):算法流程圖(圖1):圖1源代碼:/*2018/10/26 施飛宇 篤行南樓a202*/#define N 20#include <iostream>#include <stdlib.h>usi

3、ng namespace std;typedef struct pcbchar pnameN;/進程名int runtime;/運行時間int arrivetime;/到達時間int starttime;/開始運行時間 float avgtime;/帶權(quán)周轉(zhuǎn)時間char state;/進程狀態(tài) struct pcb *next;/鏈表指針PCB;PCB headinput;PCB headrun;PCB * pcbinput;void inputprocess();/建立進程函數(shù)int readydata()return 1;/判斷進程是否進入就緒函數(shù)void runprocess();/運行

4、進程函數(shù)void inputprocess()PCB *p1,*p2;cout<<"輸入進程數(shù)目"<<endl;int num;cin>>num;int i=0;p1=&headinput;p2=p1;for(i=0;i<num;i+)cout<<"輸入第"<<i+1<<"進程名,運行時間,到達時間"<<endl; scanf("%s",p1->pname);cin>>p1->runtime;c

5、in>>p1->arrivetime;p1->next=new PCB;p2=p1;p1=p1->next;delete p1;p1=NULL;p2->next=NULL;void runprocess()PCB *p1;int time=0;/時間p1=&headinput;printf("進程名到達時間服務(wù)時間開始執(zhí)行時間完成時間周轉(zhuǎn)時間帶權(quán)周轉(zhuǎn)時間n");while(p1!=NULL)if(time<p1->starttime)time=p1->starttime;p1->starttime=time

6、; p1->avgtime=(p1->starttime+p1->runtime-p1->arrivetime)*1.0/p1->runtime;time=p1->starttime+p1->runtime; printf("%s %10d %10d %10d %10d %10d %5fn",p1->pname,p1->arrivetime,p1->runtime,p1->starttime,p1->starttime+p1->runtime,p1->starttime+p1->run

7、time-p1->arrivetime,p1->avgtime); p1=p1->next;int main()inputprocess(); runprocess();return 0;運行截圖:2. 設(shè)計按短進程優(yōu)先調(diào)度算法SJF測試數(shù)據(jù):算法流程圖(圖2):是否圖2源代碼:/*2018/10/26 施飛宇 篤行南樓a202*/#define N 20#include <iostream>#include <stdlib.h>#include <stdio.h>using namespace std;typedef struct pcb

8、char pnameN;/進程名int runtime;/運行時間int arrivetime;/到達時間int starttime;/開始運行時間 float avgtime;/帶權(quán)周轉(zhuǎn)時間char state;/進程狀態(tài) struct pcb *next;/鏈表指針PCB;PCB headinput;PCB headrun;PCB * pcbinput;void inputprocess();/建立進程函數(shù)int readydata()return 1;/判斷進程是否進入就緒函數(shù)void runprocess();/運行進程函數(shù)void inputprocess()PCB *p1,*p2;

9、cout<<"輸入進程數(shù)目"<<endl;int num;cin>>num;int i=0;p1=&headinput;p2=p1;for(i=0;i<num;i+)cout<<"輸入第"<<i+1<<"進程名,到達時間,運行時間"<<endl; scanf("%s",p1->pname); cin>>p1->arrivetime;cin>>p1->runtime; p1-&g

10、t;state='a'p1->next=new PCB;p2=p1;p1=p1->next;delete p1;p1=NULL;p2->next=NULL;void runprocess() int b;PCB *p1,*p2;int time=0;/時間int runtime=0;/存儲運行最短時間int label;printf("進程名到達時間服務(wù)時間開始執(zhí)行時間完成時間周轉(zhuǎn)時間帶權(quán)周轉(zhuǎn)時間n");while(1) runtime=100; p1=&headinput; label=1; while(p1!=NULL) if(

11、p1->state!='a') p1=p1->next; continue; else / cin>>b; if(runtime>p1->runtime)&&(time>=p1->arrivetime) p2=p1; runtime=p1->runtime;/ printf("%s %dn",p1->pname,runtime); label=0; p1=p1->next; if(label) break; p2->state='b'p2->star

12、ttime=time; p2->avgtime=(p2->starttime+p2->runtime-p2->arrivetime)*1.0/p2->runtime;time=p2->starttime+p2->runtime; printf("%s %10d %10d %10d %10d %10d %15.5fn",p2->pname,p2->arrivetime,p2->runtime,p2->starttime,p2->starttime+p2->runtime,p2->starttime+p2->runtime-p2->arrivetime,p2->avgtime);int main()inputprocess();PCB *p2=&headinput;/while(p2)/ printf("%s %10d %10d %10d %10d %10d %5fn",p2->pname,p2->arrivetime,p2->runtime,p2->starttime,p2->startt

溫馨提示

  • 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

提交評論