




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、#include<stdio.h>#include<stdio.h>#include<malloc.h>typedefstructProcessNode/進(jìn)程結(jié)點(diǎn)的基本結(jié)構(gòu)charname;/進(jìn)程名intservice_time;服務(wù)時間intarrive_time;到達(dá)時間intpriority;/優(yōu)先級structFCFS_time/先到先服務(wù)intfinish_time;完成時間intturnaround_time;周轉(zhuǎn)時間floatweigtharound_time;/帶權(quán)周轉(zhuǎn)時間FCFS_time;structSJF_time短作業(yè)優(yōu)先intfin
2、ish_time;intturnaround_time;floatweigtharound_time;intflag;SJF_time;structRR_time/時間片輪轉(zhuǎn)的結(jié)點(diǎn)intfinish_time;intturnaround_time;floatweigtharound_time;intflag_time;賦值為進(jìn)程的服務(wù)時間,為。則進(jìn)程完成RR_time;structPri_time/優(yōu)先權(quán)非搶占式intfinish_time;intturnaround_time;floatweigtharound_time;Pri_time;structProcessNode*next;Pro
3、cessNode,*Linklist;voidmain()intchoice;Linklistp,head;Linklistread_information();LinklistFCFS_scheduling(Linklishead);LinklistSJF_scheduling(Linklistnead);LinklistRR_scheduling(Linklisthead);LinklistPri_scheduling(Linklisthead);head=read_information();/讀入進(jìn)程的基本信息dop=head->next;printf("n"
4、);輸出初始化后的進(jìn)程基本信息printf("*進(jìn)程初始彳t息輸出*n");/printf("n");printf("進(jìn)程名稱”);printf("到達(dá)時間");printf("服務(wù)時間");printf("優(yōu)先級");printf("n");while(p)printf("%c”,p->name);printf("%d”,p->arrive_time);printf("%d",p->service_time
5、);printf("%d”,p->priority);printf("n");p=p->next;printf("n");printf("墳*n");/輸出進(jìn)程的調(diào)用選擇項(xiàng)printf("n");printf("1、FCFS-冼至U先服務(wù)n");printf("2、SJF-短作業(yè)優(yōu)先n");printf("3、RR-時間片輪轉(zhuǎn)n");printf("4、Pri優(yōu)先權(quán)調(diào)度n");printf("5、退出n&
6、quot;);printf("n");printf("*n");printf("n");printf(“請?jiān)?5之間選擇:");scanf("%d”,&choice);printf("n");printf("n");switch(choice)(case 1: FCFS_scheduling(head);break;case 2: SJF_scheduling(head);break;case 3: RR_scheduling(head);break;case 4:
7、Pri_scheduling(head);break;/case5:exit();while(choice!=5);Linklistread_information()/進(jìn)程讀入函數(shù)(inti;intnum;/ProcessNode;Linklistpro;Linklistp;Linklisthead;printf("n");printf("墳*進(jìn)程調(diào)度算法*n");printf("n");printf("請輸入進(jìn)程的個數(shù):");scanf("%d",&num);printf("
8、;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);創(chuàng)建進(jìn)程結(jié)點(diǎn)printf("輸入第%d個進(jìn)程信息:n”,i);printf("請輸入進(jìn)程名:");fflush(stdin);scanf("%c",&pr
9、o->name);printf("到達(dá)時間:");scanf("%d”,&pro->arrive_time);printf("服務(wù)時間:");scanf("%d",&pro->service_time);printf("優(yōu)先級T:");scanf("%d”,&pro->priority);pro->next=head->next;head->next=pro;/逆序建鏈p->next=pro;p=pro;/順序建鏈/p+;p
10、ro->next=NULL;printf("n");returnhead;LinklistFCFS_scheduling(Linklisthea則到先服務(wù)算法函數(shù)Linklistp;Linklistq;指向前一進(jìn)程p=head->next;while(p)初始化進(jìn)程的完成時間、周轉(zhuǎn)時間、帶權(quán)周轉(zhuǎn)時間,初值均賦為0p->FCFS_time.finish_time=0;p->FCFS_time.turnaround_time=0;p->FCFS_time.weigtharound_time=0;p=p->next;p=q=head->n
11、ext;p->FCFS_time.finish_time=p->arrive_time;/避免第個進(jìn)程至ij達(dá)時間不為0while(p)if(p->arrive_time<=q->FCFS_time.finish_time)/T一進(jìn)程已至ij達(dá),在等待中p->FCFS_time.finish_time=(p->service_time)+(q->FCFS_time.finish_time)服務(wù)時間p->FCFS_time.turnaround_time=(p->FCFS_time.finish_time)-(p->arrive_
12、time);周轉(zhuǎn)時間p->FCFS_time.weigtharound_time=(float)(p->FCFS_time.turnaround_time)/(p->service_time);帶權(quán)周轉(zhuǎn)時間elsep->FCFS_time.finish_time=p->service_time+p->arrive_time;/艮務(wù)時間p->FCFS_time.turnaround_time=(p->FCFS_time.finish_time)-(p->arrive_time);周轉(zhuǎn)時間p->FCFS_time.weigtharound
13、_time=(float)(p->FCFS_time.turnaround_time)/(p->service_time);帶權(quán)周轉(zhuǎn)時間q=p;p=p->next;p=head->next;printf("*到先服務(wù)調(diào)度后的進(jìn)程信息printf("n");printf("進(jìn)程名稱”);printf("到達(dá)時間");printf("服務(wù)時間");printf("優(yōu)先級");printf("完成時間");printf("周轉(zhuǎn)時間”);printf
14、("帶權(quán)周轉(zhuǎn)時間”);FCFS*n");輸出先printf("n");while(p)printf("%c",p->name);printf("%d",p->arrive_time);printf("%d",p->service_time);printf("%d",p->priority);printf("%d",p->FCFS_time.finish_time);printf("%d",p->FCF
15、S_time.turnaround_time);printf("%0.2f”,p->FCFS_time.weigtharound_time);printf("n");p=p->next;printf("n");printf("墳*n");printf("n");returnhead;LinklistSJF_scheduling(Linklis1head)短作業(yè)優(yōu)先算法(Linklistp,r;Linklistq;指向前一進(jìn)程結(jié)點(diǎn)intnum=0;記錄進(jìn)程個數(shù)intadd_flag=0;進(jìn)程完成
16、服務(wù)個數(shù)intservice_time_min;intarrive_time;intk;p=head->next;首元結(jié)點(diǎn)while(p)初始化進(jìn)程的完成時間、周轉(zhuǎn)時間、帶權(quán)周轉(zhuǎn)時間,初值均賦為0(p->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
17、=p;p->SJF_time.finish_time=p->arrive_time+p->service_time;p->SJF_time.turnaround_time=(p->SJF_time.finish_time)-(p->arrive_time);倜轉(zhuǎn)時間p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/滯權(quán)周轉(zhuǎn)時間q->SJF_time.finish_time=p->SJF_time.finish
18、_time;p->SJF_time.flag=1;add_flag=1;p=p->next;doif(p->SJF_time.flag=1)p=p->next;elseif(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->ne
19、xt->service_time)<(p->service_time)service_time_min=p->next->service_time;p=p->next;elsep=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-&g
20、t;SJF_time.turnaround_time=(p->SJF_time.finish_time)-(p->arrive_time);周轉(zhuǎn)時間p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/帶權(quán)周轉(zhuǎn)時間q=p;p=r->next;elsek=0;service_time_min=p->service_time;while(p->arrive_time)<=(q->SJF_time.finish_time)&
21、amp;&k<=num)尋找最短的作業(yè)if(p->SJF_time.flag=1)p=p->next;+k;elseif(p->SJF_time.flag!=1)&&(p->service_time)<service_time_min)service_time_min=p->service_time;p=p->next;+k;elsep=p->next;+k;p=q->next;r=q;while(p->service_time!=service_time_min)p=p->next;指針指向最短作
22、業(yè)p->SJF_time.finish_time=q->SJF_time.finish_time+p->service_time;p->SJF_time.turnaround_time=(p->SJF_time.finish_time)-(p->arrive_time);周轉(zhuǎn)時間p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/帶權(quán)周轉(zhuǎn)時間p->SJF_time.flag=1;+add_flag;q=p;p=p-&
23、gt;next;q=p;p=r->next;while(add_flag!=num);for(p=head->next;num>0;num-)/斷開循環(huán)隊(duì)歹U(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á)時間");printf("服務(wù)時間");pr
24、intf("優(yōu)先級");printf("完成時間");printf("周轉(zhuǎn)時間”);printf("帶權(quán)周轉(zhuǎn)時間");printf("n");while(p)(printf("%c",p->name);printf("%d",p->arrive_time);printf("%d",p->service_time);printf("%d",p->priority);printf("%d"
25、;,p->SJF_time.finish_time);printf("%d",p->SJF_time.turnaround_time);printf("%0.2f",p->SJF_time.weigtharound_time);printf("n");p=p->next;)printf("n");printf('墳*n");printf("n");returnhead;)LinklistRR_scheduling(Linklisthead)時間片輪轉(zhuǎn)算法
26、(Linklistq;指向前一進(jìn)程結(jié)點(diǎn)Linklistp;intq_time;時間片大小intnum=0;記錄進(jìn)程個數(shù)intadd_flag=0;進(jìn)程完成服務(wù)個數(shù)printf("請輸入時間片的大?。骸?;scanf("%d",&q_time);p=head->next;while(p)初始化進(jìn)程的完成時間、周轉(zhuǎn)時間、帶權(quán)周轉(zhuǎn)時間,初值均賦為0p->RR_time.finish_time=0;p->RR_time.turnaround_time=0;p->RR_time.weigtharound_time=0;p->RR_tim
27、e.flag_time=p->service_time;q=p;+num;p=p->next;q->next=head->next;將創(chuàng)建的進(jìn)程隊(duì)歹U變?yōu)檠h(huán)隊(duì)歹1Jp=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-&g
28、t;service_time);printf("%d”,p->priority);printf("%d",p->RR_time.finish_time);printf("n");*/if(p->RR_time.flag_time)>(q_time)服務(wù)時間大于時間片p->RR_time.finish_time=(q->RR_time.finish_time)+(q_time);累加完成時間p->RR_time.flag_time=(p->RR_time.flag_time)-(q_time);if
29、(p->next->arrive_time)<=(p->RR_time.finish_time)有進(jìn)程等待q=p;p=p->next;else/當(dāng)前進(jìn)程未完成,無進(jìn)程等待,指針不向后移q=p;elseif(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.t
30、urnaround_time=(p->RR_time.finish_time)-(p->arrive_time);周轉(zhuǎn)時間p->RR_time.weigtharound_time=(float)(p->RR_time.turnaround_time)/(p->service_time);帶權(quán)周轉(zhuǎn)時間if(p->next->arrive_time)<(p->RR_time.finish_time)有進(jìn)程等待q=p;p=p->next;else/當(dāng)前進(jìn)程完成,無進(jìn)程等待,指針向后移/q=p;q->RR_time.finish_time=p->next->arrive_time;
溫馨提示
- 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 古建門樓租賃合同
- 分項(xiàng)工程勞務(wù)分包合同
- 基坑噴錨支護(hù)勞務(wù)分包合同
- 建實(shí)務(wù)招標(biāo)與合同管理知識點(diǎn)
- 私人教練健身指導(dǎo)服務(wù)合同與免責(zé)條款
- 產(chǎn)品銷售服務(wù)合同
- 個人林地承包合同
- 北京平安普惠合同
- 石子黃沙購銷合同
- 《第14課 循環(huán)結(jié)構(gòu)(二)》教學(xué)設(shè)計(jì)教學(xué)反思-2023-2024學(xué)年小學(xué)信息技術(shù)浙教版23五年級下冊
- 因公出國(境)管理辦法
- 別讓心態(tài)毀了你:受益一生的情緒掌控法
- 電梯控制技術(shù)PPT完整全套教學(xué)課件
- 甲狀腺旁腺分泌的激素及功能
- 中央財(cái)政成品油價格調(diào)整對漁業(yè)補(bǔ)助資金項(xiàng)目實(shí)施方案
- PFMEA模板完整版文檔
- 論生產(chǎn)安全對于家庭的重要性
- 風(fēng)力發(fā)電變槳系統(tǒng)外文翻譯
- 教學(xué)能力比賽決賽 《英語》教案
- ECMO IABP完整版可編輯
- 離婚糾紛證據(jù)清單
評論
0/150
提交評論