實驗報告一(進程調度算法)_第1頁
實驗報告一(進程調度算法)_第2頁
實驗報告一(進程調度算法)_第3頁
實驗報告一(進程調度算法)_第4頁
實驗報告一(進程調度算法)_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、江西師范大學計算機信息工程學院學生實驗報告專業(yè) 12級物聯(lián)網(wǎng)班 姓名 嚴超 學號 1208067042 日期 2014/05/8 課程名稱操作系統(tǒng)教程實驗室名稱W4313實驗名稱進程調度算法指導教師張練興成績1、 實驗目的用代碼實現(xiàn)模擬操作系統(tǒng)的進程調度,以加深對進程的概念及進程調度算法的理解2、 實驗原理和內容(1)先來先服務(FCFS)調度算法:從“就緒隊列”中選擇一個最先進入隊列的進程,為它分配處理器,使之開始運行。(2)優(yōu)先數(shù)調度算法:根據(jù)進程的情況或要求賦予進程一個優(yōu)先級,進程運行過程中優(yōu)先級不再改變。每次調度時,就緒隊列中優(yōu)先級最高的進程被率先調度,同級的采用先來先服務(FCFS)

2、。3、 實驗步驟進程調度算法:(1) 編寫進程控制塊數(shù)據(jù)結構(2) 統(tǒng)一按照FCFS調度算法創(chuàng)建隊列(3) 在FCFS調度算法中,將就緒隊列隊首進程調入執(zhí)行,如果在隊列中存在到達時間小于等于當前時間的結點,將該結點的狀態(tài)設為就緒狀態(tài)。如果當前進程執(zhí)行完了,就將其狀態(tài)改為完成狀態(tài),并將其插入到隊尾。(4) 在優(yōu)先級調度算法中,將就緒隊列隊首進程調入執(zhí)行,如果在隊列中存在到達時間小于等于當前時間的結點,將該結點的狀態(tài)設為就緒狀態(tài),并對隊列中的結點按優(yōu)先級數(shù)的大小進行排序(隊首除外)。如果當前進程執(zhí)行完了,就將其狀態(tài)改為完成狀態(tài),并將其插入到隊尾。(5) 輸出運行后的結果,如周轉時間和帶權周轉時間。

3、4、 程序及運行結果(或實驗數(shù)據(jù)記錄及分析)進程調度算法: 本次實驗讓我更加明白進程調度的概念,更加了解進程調度的工作原理。在前期,我是直接將結果顯示出來,后來,我又在原有的基礎上加了顯示每一時刻隊列的信息。在編寫此代碼過程中遇到很多問題,例如指針問題,指針指來指去,總是指錯地址。具體代碼:#include#include#define MAX 1000typedef struct progressint ID;/進程名 char state; /進程狀態(tài) int super; /優(yōu)先數(shù) int arrive_time;/到達時間 int serve_time;/服務時間 struct pro

4、gress *next;node;node* sortFCFS(node* head,node* q)node *p,*pre; int done=0; if(head=NULL)|(q-arrive_time)arrive_time) /*到達時間最先者,插入隊首*/ q-next=head; head=q; else /* 進程比較到達時間,插入適當?shù)奈恢弥?/ p=head; pre=p-next; while(pre!=NULL) if(q-arrive_time)arrive_time) /*若插入進程比當前進程到達時間小,*/ /*插入到當前進程前面*/ q-next=pre; p

5、-next=q; pre=NULL; done=1; else p=p-next; pre=pre-next; if(done=0) p-next=q; return head;/*函數(shù)功能:創(chuàng)建單鏈表參數(shù):空返回值:指向節(jié)點的指針head */node* create()node *head;node *p,*q;int x,count=0;head=NULL;printf(ntt請輸入進程名【輸入-1結束】:);while(scanf(%d,&x)!=EOF & x!= -1)p=(node *)malloc(sizeof(node);printf(tt請輸入優(yōu)先級數(shù)【優(yōu)先數(shù)高者優(yōu)先】:)

6、;scanf( %d,&p-super);printf(tt請輸入到達時間【到達時間不得小于0】:);scanf( %d,&p-arrive_time);printf(tt請輸入服務時間【服務時間必須大于0】:);scanf( %d,&p-serve_time);p-ID=x;p-state=w; p-next=NULL; head=sortFCFS(head,p);printf(ntt請輸入進程名(輸入-1結束):);return head;/*函數(shù)功能:輸出單鏈表參數(shù):指向節(jié)點的指針head返回值:空*/void print(node *head) node *p;printf(nt|-結

7、點信息情況-|);printf(ntt| 進程名 |優(yōu)先級數(shù)|到達時間|服務時間| 狀態(tài) |);p=head;while(p)printf(ntt|%8d|%8d|%8d|%8d|%8c|,p-ID,p-super,p-arrive_time,p-serve_time,p-state);p=p-next;printf(nt|-結點信息情況-|n);/*函數(shù)功能:利用先來先服務調度算法 參數(shù):指向節(jié)點的指針head返回值:空存在問題: */void FCFS(node* head)int start_time,finish_time=0,round_time,all_time=0;int don

8、e=1;int clock=0;float right_round_time;node* p,*q,*flag;flag=p=head;clock=p-arrive_time;all_time=start_time=head-arrive_time;while(p)all_time+=p-serve_time;p=p-next;p=head;while(done)done=0;printf(nnt|-第%2d 時刻-|,clock);while(p)if(p-arrive_timestate=w|p-state=r)p-state=r;done=1;p=p-next;while(flag-ne

9、xt)flag=flag-next;print(head);printf(t|-第%2d 時刻-|nn,clock);if(clock=all_time)break;clock+;finish_time=start_time+head-serve_time;if(finish_time=clock)head-state=f;flag-next=head;head=head-next;flag=flag-next;flag-next=NULL;start_time=finish_time;p=head;p=head;finish_time=p-arrive_time; printf(t|-FCF

10、S調度算法-|);printf(nt| 進程名 |到達時間|服務時間|開始時間|完成時間|周轉時間|帶權周轉|);while(p)if(p-arrive_timearrive_time;finish_time=start_time+p-serve_time;round_time=finish_time-p-arrive_time;right_round_time=(float)round_time/p-serve_time;printf(nt|%8d|%8d|%8d|%8d|%8d|%8d|%8.2f|,p-ID,p-arrive_time,p-serve_time,start_time,fi

11、nish_time,round_time,right_round_time);p=p-next;printf(nt|-FCFS調度算法-|);printf(n);void SortBySuper(node *head)node *p1,*q1,*temp;temp=(node*)malloc(sizeof(node);for(p1=head-next;p1!=NULL&p1-state=r;p1=p1-next)for(q1=p1-next;q1!=NULL&q1-state=r;q1=q1-next)if(p1-supersuper)temp-ID=p1-ID;p1-ID=q1-ID;q1-

12、ID=temp-ID;temp-super=p1-super;p1-super=q1-super;q1-super=temp-super;temp-arrive_time=p1-arrive_time;p1-arrive_time=q1-arrive_time;q1-arrive_time=temp-arrive_time;temp-serve_time=p1-serve_time;p1-serve_time=q1-serve_time;q1-serve_time=temp-serve_time;temp-state=p1-state;p1-state=q1-state;q1-state=te

13、mp-state;/*函數(shù)功能:利用優(yōu)先數(shù)調度算法 參數(shù):指向節(jié)點的指針head返回值:空存在問題:*/void priority(node* head)int start_time,finish_time=0,round_time,all_time=0;int done=1;int clock=0;float right_round_time;node* p,*q,*flag;flag=p=head;clock=p-arrive_time;all_time=start_time=head-arrive_time;while(p)all_time+=p-serve_time;p=p-next;

14、p=head;while(done)done=0;printf(nnt|-第%2d 時刻-|,clock);while(p)if(p-arrive_timestate=w|p-state=r)p-state=r;done=1;p=p-next;SortBySuper(head);while(flag-next)flag=flag-next;print(head);printf(t|-第%2d 時刻-|nn,clock);if(clock=all_time)break;clock+;finish_time=start_time+head-serve_time;if(finish_time=clo

15、ck)head-state=f;flag-next=head;head=head-next;flag=flag-next;flag-next=NULL;start_time=finish_time;p=head;p=head;finish_time=p-arrive_time; printf(nt|-優(yōu)先數(shù)調度算法-|);printf(nt| 進程名 |到達時間|服務時間|開始時間|完成時間|周轉時間|帶權周轉|);while(p)if(p-arrive_timearrive_time;finish_time=start_time+p-serve_time;round_time=finish_time-p-arrive_time;right_round_time=(float)round_time/p-serve_time;printf(nt|%8d|%8d|%8d|%8d|%8d|%8d|%8.2f|,p-ID,p-arrive_time,p-serve_time,start_time,finish_time,round_time,right_round_time);p=p-next;printf(nt|-優(yōu)先數(shù)調度算法-|);printf(n);int main()char choice;node *head;doprintf(ntt|-MUNE-|n);printf

溫馨提示

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

評論

0/150

提交評論