先來先服務(wù)調(diào)度算法_第1頁
先來先服務(wù)調(diào)度算法_第2頁
先來先服務(wù)調(diào)度算法_第3頁
先來先服務(wù)調(diào)度算法_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

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

文檔簡介

1、FCFS先來先服務(wù)調(diào)度算法:#include#include#include#include#define MAX_POSSIBILITY 100 using namespace std;typedef struct PCBint sum;int PID;char Pname;bool state;int arrive_time;int start_time;int serve_time;int finish_time;創(chuàng)建進程PCB/頭結(jié)點用于存放進程的總個數(shù)進程號進程名進程運行狀態(tài)/進程到達時間進程開始時間進場服務(wù)時間進程完成時間float turn_around_time; /進程周轉(zhuǎn)時

2、間float weight_turn_around_time; 進程帶權(quán)周轉(zhuǎn)時間 PCB *next;PCB;void InitHead(PCB *p)(PCB *q = p;q-PID=-1;q-Pname=-1;q-state=false;q-arrive_time=0;/指向下一個進程/ true代表未被執(zhí)行初始化到達時間q-serve_time=0;隨機產(chǎn)生進程服務(wù)時間q-start_time=0;有待于計算的時間q-finish_time=0;q-turn_around_time=0;q-weight_turn_around_time=0;q-next=NULL;void Creat

3、ePCB(PCB *p)隨機創(chuàng)建進程int N,pid=0,arrive_time=0;char pname=A;cinN;創(chuàng)建的進程數(shù)PCB *head=p;head-sum=N;srand( (unsigned)time( NULL );設(shè)置隨機數(shù)種子while(N-)PCB *q=(PCB *)malloc(sizeof(PCB);q-PID=pid;q-Pname=pname;q-state=true;/ true 代表未被執(zhí)行q-arrive_time=arrive_time;初始化到達時間q-serve_time=rand() % MAX_POSSIBILITY; /隨機產(chǎn)生進程服

4、務(wù)時間q-start_time=0;有待于計算的時間q-finish_time=0;q-turn_around_time=0;q-weight_turn_around_time=0;q-next=NULL;head-next=q;head=head-next;pid+;pname+;arrive_time+;void Run_FCFS(PCB *p)PCB *head=p;head-state=false;表示已經(jīng)執(zhí)行while(head-start_timearrive_time)head-start_time+;head-finish_time=head-start_time+head-s

5、erve_time;完成時間=開始時間+服務(wù)時間 head-turn_around_time=head-finish_time-head-arrive_time;/凋 轉(zhuǎn)時間=完成-到達 head-weight_turn_around_time=head-turn_around_time/head-serve_time;if(head-next)head-next-start_time=head-finish_time; /下一個進程開始=這個進程的完成 cout進程號進程名運行狀態(tài)到達時間服務(wù)時間開始時間完成時間周轉(zhuǎn)時間帶權(quán)周轉(zhuǎn)時間endl;cout PIDt Pnamet statet arrive_timet serve_timet start_timet finish_timetturn_around_timetweight_turn_around_timetnnext; while(head) if(head-state) Run_FCFS(head); head=head-next; void main() PCB *

溫馨提示

  • 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論