



版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、#include<stdio.h>#include<stdio.h>#include<malloc.h>typedef struct ProcessNode/進(jìn)程結(jié)點(diǎn)的基本結(jié)構(gòu)char name;/ 進(jìn)程名int service_time;/ 服務(wù)時(shí)間int arrive_time;/ 到達(dá)時(shí)間int priority;/ 優(yōu)先級(jí)struct FCFS_time/ 先到先服務(wù)int finish_time;/ 完成時(shí)間int turnaround_time;/ 周轉(zhuǎn)時(shí)間float weigtharound_time;/ 帶權(quán)周轉(zhuǎn)時(shí)間FCFS_time;str
2、uct SJF_time/ 短作業(yè)優(yōu)先int finish_time;int turnaround_time;float weigtharound_time;int flag;SJF_time;struct RR_time/ 時(shí)間片輪轉(zhuǎn)的結(jié)點(diǎn)int finish_time;int turnaround_time;float weigtharound_time;int flag_time;/ 賦值為進(jìn)程的服務(wù)時(shí)間,為0 則進(jìn)程完成RR_time;struct Pri_time/ 優(yōu)先權(quán)非搶占式int finish_time;int turnaround_time;float weigtharou
3、nd_time;Pri_time;struct ProcessNode*next;ProcessNode,*Linklist;void main()int choice;Linklistp,head;Linklist read_information();Linklist FCFS_scheduling(Linklisthead);Linklist SJF_scheduling(Linklisthead);Linklist RR_scheduling(Linklisthead);Linklist Pri_scheduling(Linklist head);head=read_informati
4、on();/ 讀入進(jìn)程的基本信息dop=head->next;printf("n");printf("* 進(jìn)程初始信息輸出 * n"); / 輸出初始化后的進(jìn)程基本信息 printf("n");printf("進(jìn)程名稱");printf("到達(dá)時(shí)間");printf("服務(wù)時(shí)間");printf("優(yōu)先級(jí)");printf("n");while(p)printf("%c ",p->name);printf
5、("%d",p->arrive_time);printf("%d",p->service_time);printf("%d ",p->priority);printf("n");p=p->next;printf("n");printf("* n");/ 輸出進(jìn)程的調(diào)用選擇項(xiàng) printf("n");printf("1、FCFS-先到先服務(wù)n");printf("2、SJF-短作業(yè)優(yōu)先n");p
6、rintf("3、RR-時(shí)間片輪轉(zhuǎn)n");printf("4、Pri-優(yōu)先權(quán)調(diào)度n");printf("5、退出 n");printf("n");printf("* n");printf("n");printf("請(qǐng)?jiān)?1 5 之間選擇 :");scanf("%d",&choice);printf("n");printf("n");switch(choice)case 1:FCFS_sch
7、eduling(head);break;case 2:SJF_scheduling(head);break;case 3:RR_scheduling(head);break;case 4:Pri_scheduling(head);break;/ case 5: exit();while(choice!=5);Linklist read_information()/進(jìn)程讀入函數(shù)int i;intnum;/ ProcessNode ;Linklist pro;Linklist p;Linklist head;printf("n");printf("*進(jìn)程調(diào)度算法 *
8、n");printf("n");printf("請(qǐng)輸入進(jìn)程的個(gè)數(shù):");scanf("%d",&num);printf("n");printf("*初始化信息 * n");printf("n");head=(Linklist)malloc(sizeof(ProcessNode);/頭結(jié)點(diǎn)head->next=NULL;p=head;for(i=1;i<=num;i+)pro=(Linklist)malloc(sizeof(ProcessNode)
9、;/創(chuàng)建進(jìn)程結(jié)點(diǎn)printf(" 輸入第 %d 個(gè)進(jìn)程信息 :n",i);printf("請(qǐng)輸入進(jìn)程名 : ");fflush(stdin);scanf("%c",&pro->name);printf("到達(dá)時(shí)間 : ");scanf("%d",&pro->arrive_time);printf("服務(wù)時(shí)間 : ");scanf("%d",&pro->service_time);printf("優(yōu)先級(jí) :
10、 ");scanf("%d",&pro->priority);/pro->next=head->next;head->next=pro;/ 逆序建鏈p->next=pro;p=pro;/ 順序建鏈/p+;pro->next=NULL;printf("n");return head;Linklist FCFS_scheduling(Linklist head)/先到先服務(wù)算法函數(shù)Linklist p;Linklist q;/指向前一進(jìn)程p=head->next;while(p) / 初始化進(jìn)程的完
11、成時(shí)間、周轉(zhuǎn)時(shí)間、帶權(quán)周轉(zhuǎn)時(shí)間,初值均賦為0p->FCFS_time.finish_time=0;p->FCFS_time.turnaround_time=0;p->FCFS_time.weigtharound_time=0;p=p->next;p=q=head->next;p->FCFS_time.finish_time=p->arrive_time;/避免第一個(gè)進(jìn)程到達(dá)時(shí)間不為0while(p)if(p->arrive_time<=q->FCFS_time.finish_time)/下一進(jìn)程已到達(dá),在等待中p->FCFS_t
12、ime.finish_time=(p->service_time)+(q->FCFS_time.finish_time);/服務(wù)時(shí)間p->FCFS_time.turnaround_time=(p->FCFS_time.finish_time)-(p->arrive_time);/周轉(zhuǎn)時(shí)間p->FCFS_time.weigtharound_time=(float)(p->FCFS_time.turnaround_time)/(p->service_time);/帶權(quán)周轉(zhuǎn)時(shí)間elsep->FCFS_time.finish_time=p->
13、service_time+p->arrive_time;/服務(wù)時(shí)間p->FCFS_time.turnaround_time=(p->FCFS_time.finish_time)-(p->arrive_time);/周轉(zhuǎn)時(shí)間p->FCFS_time.weigtharound_time=(float)(p->FCFS_time.turnaround_time)/(p->service_time);/帶權(quán)周轉(zhuǎn)時(shí)間q=p;p=p->next;p=head->next;printf("*FCFS *n");/ 輸出先到先服務(wù)調(diào)度后
14、的進(jìn)程信息printf("n");printf("進(jìn)程名稱");printf("到達(dá)時(shí)間");printf("服務(wù)時(shí)間");printf("優(yōu)先級(jí)");printf("完成時(shí)間");printf("周轉(zhuǎn)時(shí)間");printf("帶權(quán)周轉(zhuǎn)時(shí)間");printf("n");while(p)printf("printf("printf("printf("printf("pr
15、intf("printf("%c ",p->name);%d",p->arrive_time);%d",p->service_time);%d ",p->priority);%d",p->FCFS_time.finish_time);%d",p->FCFS_time.turnaround_time);%0.2f",p->FCFS_time.weigtharound_time);printf("n");p=p->next;printf(&q
16、uot;n");printf("* n");printf("n");return head;Linklist SJF_scheduling(Linklisthead)/ 短作業(yè)優(yōu)先算法Linklist p,r;Linklist q;/指向前一進(jìn)程結(jié)點(diǎn)int num=0;/ 記錄進(jìn)程個(gè)數(shù)int add_flag=0;/ 進(jìn)程完成服務(wù)個(gè)數(shù)int service_time_min;int arrive_time;int k;p=head->next;/ 首元結(jié)點(diǎn)while(p) / 初始化進(jìn)程的完成時(shí)間、周轉(zhuǎn)時(shí)間、帶權(quán)周轉(zhuǎn)時(shí)間,初值均賦為0p-
17、>SJF_time.finish_time=0;p->SJF_time.turnaround_time=0;p->SJF_time.weigtharound_time=0;p->SJF_time.flag=0;+num;q=p;p=p->next;q->next=head->next;/ 將創(chuàng)建的進(jìn)程隊(duì)列變?yōu)檠h(huán)隊(duì)列p=head->next;q=p;p->SJF_time.finish_time=p->arrive_time+p->service_time;p->SJF_time.turnaround_time=(p-&g
18、t;SJF_time.finish_time)-(p->arrive_time);/周轉(zhuǎn)時(shí)間p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/帶 權(quán)周 轉(zhuǎn)時(shí)間q->SJF_time.finish_time=p->SJF_time.finish_time;p->SJF_time.flag=1;add_flag=1;p=p->next;doif(p->SJF_time.flag=1)p=p->next;else if(
19、p->arrive_time)>(q->SJF_time.finish_time)service_time_min=p->service_time;arrive_time=p->arrive_time;while(p->arrive_time=arrive_time&&p->SJF_time.flag=0)/尋找最短的作業(yè)if(p->next->service_time)<(p->service_time)service_time_min=p->next->service_time;p=p->n
20、ext; else p=p->next;p=q->next;r=q;while(p->service_time!=service_time_min)p=p->next;/指針指向最短作業(yè)p->SJF_time.finish_time=p->arrive_time+p->service_time;p->SJF_time.flag=1;+add_flag;p->SJF_time.turnaround_time=(p->SJF_time.finish_time)-(p->arrive_time);/周 轉(zhuǎn)時(shí)間p->SJF_tim
21、e.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/帶權(quán)周轉(zhuǎn)時(shí)間 q=p;p=r->next;elsek=0;service_time_min=p->service_time;while(p->arrive_time)<=(q->SJF_time.finish_time)&&k<=num)/尋找最短的作業(yè)if(p->SJF_time.flag=1) p=p->next;+k;elseif(p->SJF_time.f
22、lag!=1)&&(p->service_time)<service_time_min) service_time_min=p->service_time; p=p->next;+k;else p=p->next;+k; p=q->next;r=q;while(p->service_time!=service_time_min)p=p->next;/指針指向最短作業(yè) p->SJF_time.finish_time=q->SJF_time.finish_time+p->service_time; p->SJF
23、_time.turnaround_time=(p->SJF_time.finish_time)-(p->arrive_time);/周 轉(zhuǎn)時(shí)間p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/帶權(quán)周轉(zhuǎn)時(shí)間 p->SJF_time.flag=1;+add_flag;/q=p;p=p->next;q=p;p=r->next;while(add_flag!=num);for(p=head->next;num>0;num-
24、)/ 斷開(kāi)循環(huán)隊(duì)列q=p;p=p->next;q->next=NULL;p=head->next;/ 指向鏈?zhǔn)?,輸出短作業(yè)調(diào)度后的進(jìn)程信息printf("n");printf("* SJF * n"); printf("n");printf("進(jìn)程名稱");printf("到達(dá)時(shí)間");printf("服務(wù)時(shí)間");printf("優(yōu)先級(jí)");printf("完成時(shí)間");printf("周轉(zhuǎn)時(shí)間"
25、);printf("帶權(quán)周轉(zhuǎn)時(shí)間");printf("n");while(p)printf("printf("printf("printf("printf("printf("printf("%c ",p->name);%d",p->arrive_time);%d",p->service_time);%d ",p->priority);%d",p->SJF_time.finish_time);%d"
26、,p->SJF_time.turnaround_time);%0.2f",p->SJF_time.weigtharound_time);printf("n");p=p->next;printf("n");printf("* n");printf("n");return head;Linklist RR_scheduling(Linklisthead)/ 時(shí)間片輪轉(zhuǎn)算法Linklist q;/指向前一進(jìn)程結(jié)點(diǎn)Linklist p;int q_time;/ 時(shí)間片大小int num=0;/
27、記錄進(jìn)程個(gè)數(shù)int add_flag=0;/ 進(jìn)程完成服務(wù)個(gè)數(shù)printf("請(qǐng)輸入時(shí)間片的大小:");scanf("%d",&q_time);p=head->next;while(p) / 初始化進(jìn)程的完成時(shí)間、周轉(zhuǎn)時(shí)間、帶權(quán)周轉(zhuǎn)時(shí)間,初值均賦為0p->RR_time.finish_time=0;p->RR_time.turnaround_time=0;p->RR_time.weigtharound_time=0;p->RR_time.flag_time=p->service_time;q=p;+num;p=
28、p->next;q->next=head->next;/ 將創(chuàng)建的進(jìn)程隊(duì)列變?yōu)檠h(huán)隊(duì)列p=head->next;q->RR_time.finish_time=p->arrive_time;do/* printf("n");printf("* n");printf("%c ",p->name);printf("%d",p->arrive_time);printf("%d",p->service_time);printf("%d &qu
29、ot;,p->priority);printf("%d",p->RR_time.finish_time);printf("n"); */if(p->RR_time.flag_time)>(q_time)/ 服務(wù)時(shí)間大于時(shí)間片p->RR_time.finish_time=(q->RR_time.finish_time)+(q_time);/累加完成時(shí)間 p->RR_time.flag_time=(p->RR_time.flag_time)-(q_time);if(p->next->arrive_t
30、ime)<=(p->RR_time.finish_time)/有進(jìn)程等待 q=p;p=p->next; else/ 當(dāng)前進(jìn)程未完成,無(wú)進(jìn)程等待,指針不向后移 q=p; else if(p->RR_time.flag_time)=0)/ 進(jìn)程已經(jīng)完成p=p->next;elsep->RR_time.finish_time=(q->RR_time.finish_time)+(p->RR_time.flag_time);p->RR_time.flag_time=0; +add_flag;p->RR_time.turnaround_time=
31、(p->RR_time.finish_time)-(p->arrive_time);/ 周轉(zhuǎn)時(shí)間p->RR_time.weigtharound_time=(float)(p->RR_time.turnaround_time)/(p->service_time);/ 帶權(quán)周轉(zhuǎn)時(shí)間if(p->next->arrive_time)<(p->RR_time.finish_time)/ 有進(jìn)程等待 q=p;p=p->next; else/ 當(dāng)前進(jìn)程完成,無(wú)進(jìn)程等待,指針向后移/q=p; q->RR_time.finish_time=p->next->arrive_time;p=p->next;q=p;q->RR_time.finish_time=p->arrive_time;while(add_flag!=num);/while(p->RR_time.f
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 日語(yǔ)作文報(bào)告范文
- 商業(yè)化運(yùn)營(yíng)知識(shí)培訓(xùn)課件
- 輕工實(shí)習(xí)報(bào)告范文
- 2025年度熱處理設(shè)備技術(shù)培訓(xùn)與指導(dǎo)合同
- 二零二五年度借調(diào)人員工作培訓(xùn)與職業(yè)成長(zhǎng)協(xié)議
- 2025年汽修店轉(zhuǎn)讓與員工安置一體化服務(wù)合同
- 2025年度餐飲智能化升級(jí)入股協(xié)議
- 二零二五年度文化教育項(xiàng)目授權(quán)委托協(xié)議書
- 2025年度認(rèn)繳制環(huán)保產(chǎn)業(yè)股權(quán)轉(zhuǎn)讓協(xié)議書
- 二零二五年度婚慶活動(dòng)演藝服務(wù)合同(含燈光舞美)
- 新條令.新亮點(diǎn)-內(nèi)務(wù)條令解讀
- 中醫(yī)適宜技術(shù)-中藥熱奄包
- 林海雪原課件6張
- 銀發(fā)經(jīng)濟(jì)產(chǎn)業(yè)發(fā)展規(guī)劃
- 防火涂料質(zhì)量保證書
- 礦產(chǎn)資源開(kāi)發(fā)合同備忘錄范本
- 大模型在刑偵技術(shù)中的應(yīng)用探索
- 肝硬化課件(共45張)
- 家長(zhǎng)會(huì)課件:小學(xué)語(yǔ)文二年級(jí)家長(zhǎng)會(huì)課件
- 2024年西安電力高等??茖W(xué)校單招職業(yè)技能測(cè)試題庫(kù)及答案解析
- 2024年中國(guó)科學(xué)技術(shù)大學(xué)創(chuàng)新班物理試題答案詳解
評(píng)論
0/150
提交評(píng)論