




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上學號E 專業(yè)計算機科學與技術 姓名施飛宇實驗日期2018/10/25 教師簽字 成績實驗報告【實驗名稱】 進程調(diào)度【實驗目的】鞏固和加深處理機調(diào)度的概念。設計調(diào)度算法,模擬實現(xiàn)處理機的調(diào)度【實驗原理】先來先服務(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. 設計先來先服務調(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("進程名到達時間服務時間開始執(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. 設計按短進程優(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("進程名到達時間服務時間開始執(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)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 企業(yè)價值創(chuàng)造試題及答案
- 2025年項目可行性研究報告(技術工藝+設備選型+財務概算+廠區(qū)規(guī)劃)方案設計
- 人民陪審員試題及答案
- 2025年農(nóng)村電商服務站農(nóng)村電商產(chǎn)品創(chuàng)新與市場拓展報告
- 2025年農(nóng)村電商扶貧資金申請政策實施效果與農(nóng)村電商創(chuàng)新發(fā)展報告
- 油漆考試題答案及解析
- 蠅王考試題目及答案
- 2025年農(nóng)產(chǎn)品質(zhì)量安全追溯體系與農(nóng)業(yè)人才培養(yǎng)的互動關系
- 2025年農(nóng)產(chǎn)品質(zhì)量安全檢測技術發(fā)展與應用報告
- 音樂學院面試題庫及答案
- 2022年貴州省貴陽市(初三學業(yè)水平考試)中考生物試卷及答案
- 患者日常生活護理
- 消防接警員應知應會考試題庫大全-上(單選、多選題)
- 07J623-3 天窗擋風板及擋雨片
- 2021年西藏中考地理真題
- 福州市勞動合同書(2007年11月印制)
- 梨園助手:全年病蟲害防治歷
- MOOC 大學物理(上)-西北工業(yè)大學 中國大學慕課答案
- 銷售部廉政培訓課件
- 烏拉波拉故事全集
- 伊朗鋼結(jié)構(gòu)包裝專項方案
評論
0/150
提交評論