




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、實驗一 進程調(diào)度實驗一、 根據(jù)實習指導(dǎo)中給出的代碼框架,補充代碼完成相應(yīng)的功能。采用“最高優(yōu)先數(shù)優(yōu)先”調(diào)度算法對五個進程進行調(diào)度。動態(tài)優(yōu)先數(shù)調(diào)度算法代碼:#include "stdio.h"#include <stdlib.h>#include <conio.h>#define getpch(type) (type*)malloc(sizeof(type)#define NULL 0struct pcb /* 定義進程控制塊PCB */char name10;char state;int super;int ntime;int rtime;struc
2、t pcb* link;*ready=NULL,*p;typedef struct pcb PCB;sort() /* 建立對進程進行優(yōu)先級排列函數(shù)*/PCB *first, *second;int insert=0;if(ready=NULL)|(p->super)>(ready->super) /*優(yōu)先級最大者,插入隊首*/p->link=ready;ready=p;else /* 進程比較優(yōu)先級,插入適當?shù)奈恢弥?/first=ready;second=first->link;while(second!=NULL)if(p->super)>(se
3、cond->super) /*若插入進程比當前進程優(yōu)先數(shù)大,*/ /*插入到當前進程前面*/p->link=second;first->link=p;second=NULL;insert=1;else /* 插入進程優(yōu)先數(shù)最低,則插入到隊尾*/first=first->link;second=second->link;if(insert=0) first->link=p;input() /* 建立進程控制塊函數(shù)*/int i,num;system("cls"); /*清屏*/printf("n 請輸入進程個數(shù):");s
4、canf("%d",&num);for(i=1;i<=num;i+)printf("n 進程號No.%d:n",i);p=getpch(PCB);printf("n 輸入進程名:");scanf("%s",p->name);printf("n 輸入進程優(yōu)先數(shù):");scanf("%d",&p->super);printf("n 輸入進程運行時間:");scanf("%d",&p->ntim
5、e);printf("n");p->rtime=0;p->state='w'p->link=NULL;sort(); /* 調(diào)用sort函數(shù)*/int space()int l=0; PCB* pr=ready;while(pr!=NULL)l+;pr=pr->link;return(l);disp(PCB * pr) /*建立進程顯示函數(shù),用于顯示當前進程*/printf("n qname t state t super t ndtime t runtime n");printf("|%st"
6、,pr->name);printf("|%ct",pr->state);printf("|%dt",pr->super);printf("|%dt",pr->ntime);printf("|%dt",pr->rtime);printf("n");check() /* 建立進程查看函數(shù) */PCB* pr;printf("n * 當前正在運行的進程是:%s",p->name); /*顯示當前運行進程*/disp(p);pr=ready;pri
7、ntf("n *當前就緒隊列狀態(tài)為:n"); /*顯示就緒隊列狀態(tài)*/while(pr!=NULL)disp(pr);pr=pr->link;destroy() /*建立進程撤消函數(shù)(進程運行結(jié)束,撤消進程)*/printf("n 進程 %s 已完成.n",p->name);free(p);running() /* 建立進程就緒函數(shù)(進程運行時間到,置就緒狀態(tài)*/(p->rtime)+;if(p->rtime=p->ntime)destroy(); /* 調(diào)用destroy函數(shù)*/else(p->super)-;p-&
8、gt;state='w'sort(); /*調(diào)用sort函數(shù)*/main() /*主函數(shù)*/int len,h=0;char ch;input();len=space();while(len!=0)&&(ready!=NULL)ch=getchar();h+;printf("n The execute number:%d n",h);p=ready;ready=p->link;p->link=NULL;p->state='R'check();running();printf("n 按任一鍵繼續(xù).&q
9、uot;);ch=getchar();printf("nn 進程已經(jīng)完成.n");ch=getchar();二、 畫出數(shù)據(jù)結(jié)構(gòu)(eg. PCB、優(yōu)先級隊列)圖、代碼的整體和局部結(jié)構(gòu)流程圖。 三、 對不同階段的執(zhí)行結(jié)果進行截圖,并對截圖進行說明。 采用“最高優(yōu)先數(shù)優(yōu)先”調(diào)度算法對五個進程進行調(diào)度。靜態(tài)優(yōu)先數(shù)調(diào)度算法代碼:將動態(tài)優(yōu)先數(shù)算法代碼中的120行:(p->super)-;注釋即為靜態(tài)優(yōu)先數(shù)算法結(jié)果截圖: 編寫并調(diào)試一個模擬的進程調(diào)度程序,采用“輪轉(zhuǎn)法”調(diào)度算法對五個進程進行調(diào)度。簡單輪轉(zhuǎn)法代碼:#include "stdio.h"#includ
10、e <stdlib.h>#include <conio.h>#define getpch(type) (type*)malloc(sizeof(type)#define NULL 0struct pcb /* 定義進程控制塊PCB */ char name10; char state; int super; int ntime; int rtime; struct pcb* link;*ready=NULL,*p;typedef struct pcb PCB;sort() /* 建立對進程進行優(yōu)先級排列函數(shù)*/ PCB *first, *second; int inse
11、rt=0; if(ready=NULL)|(p->super)>(ready->super) /*優(yōu)先級最大者,插入隊首*/ p->link=ready; ready=p; else /* 進程比較優(yōu)先級,插入適當?shù)奈恢弥?/ first=ready; second=first->link; while(second!=NULL) if(p->super)>(second->super) /*若插入進程比當前進程優(yōu)先數(shù)大,*/ /*插入到當前進程前面*/ p->link=second; first->link=p; second=NU
12、LL; insert=1; else /* 插入進程優(yōu)先數(shù)最低,則插入到隊尾*/ first=first->link; second=second->link; if(insert=0) first->link=p; input() /* 建立進程控制塊函數(shù)*/ int i,num; system("cls"); /*清屏*/ printf("n 請輸入進程個數(shù):"); scanf("%d",&num); for(i=1; i<=num; i+) printf("n 進程號No.%d:n&qu
13、ot;,i); p=getpch(PCB); printf("n 輸入進程名:"); scanf("%s",p->name); p->super=0; printf("n 輸入進程運行時間:"); scanf("%d",&p->ntime); printf("n"); p->rtime=0; p->state='w' p->link=NULL; sort(); /* 調(diào)用sort函數(shù)*/ int space() int l=0; PCB
14、* pr=ready; while(pr!=NULL) l+; pr=pr->link; return(l);disp(PCB * pr) /*建立進程顯示函數(shù),用于顯示當前進程*/ printf("n qname t state t ndtime runtime n"); printf("|%st",pr->name); printf("|%ct",pr->state); printf("|%dt",pr->ntime); printf("|%dt",pr->rt
15、ime); printf("n");check() /* 建立進程查看函數(shù) */ PCB* pr; printf("n * 當前正在運行的進程是:%s",p->name); /*顯示當前運行進程*/ disp(p); pr=ready; printf("n *當前就緒隊列狀態(tài)為:n"); /*顯示就緒隊列狀態(tài)*/ while(pr!=NULL) disp(pr); pr=pr->link; destroy() /*建立進程撤消函數(shù)(進程運行結(jié)束,撤消進程)*/ printf("n 進程 %s 已完成.n"
16、;,p->name); free(p);running() /* 建立進程就緒函數(shù)(進程運行時間到,置就緒狀態(tài)*/ (p->rtime)+; if(p->rtime=p->ntime) destroy(); /* 調(diào)用destroy函數(shù)*/ else /(p->super)-; p->state='w' sort(); /*調(diào)用sort函數(shù)*/ main() /*主函數(shù)*/ int len,h=0; char ch; input(); len=space(); while(len!=0)&&(ready!=NULL) ch=getchar(); h+; printf("n The execute number:%d n",h); p=ready; ready=p->link; p->link=NULL; p->state='R' check(); running(); printf("n 按任一鍵繼續(xù)."); ch=getchar(); printf("nn 進程已經(jīng)完成.n"); ch=getch
溫馨提示
- 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)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司提成策劃方案(3篇)
- 推門聽課活動方案(3篇)
- 醫(yī)院食堂人群管理制度
- 室內(nèi)小房改造方案(3篇)
- 停水設(shè)備檢修方案(3篇)
- 醫(yī)院設(shè)備故障管理制度
- 建安企業(yè)倉儲管理制度
- 關(guān)于餐廳衛(wèi)生管理制度
- 物業(yè)地面改造方案(3篇)
- 危險崗位應(yīng)急管理制度
- 炊事員安全試題及答案
- 計算機基礎(chǔ)考試知識試題及答案集
- 2025年下半年北京市昌平區(qū)東小口鎮(zhèn)招聘擬聘用易考易錯模擬試題(共500題)試卷后附參考答案
- 馬幫運輸協(xié)議書
- 山東省棗莊市市中學區(qū)五校聯(lián)考2025屆七年級數(shù)學第二學期期末考試模擬試題含解析
- 2025年中考道德與法治三輪沖刺:人工智能+文化建設(shè) 考題含答案
- 數(shù)字智慧方案未來醫(yī)院智慧孿生和空間創(chuàng)新
- 福建廈門雙十中學2025屆物理八下期末質(zhì)量跟蹤監(jiān)視試題含解析
- 2025年消防執(zhí)業(yè)資格考試題庫(消防應(yīng)急救援裝備)消防設(shè)備操作規(guī)程試題
- 2024-2025學年四川省成都市高一語文下學期期末考試試卷(含答案)
- 制藥生產(chǎn)管理培訓
評論
0/150
提交評論