版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include<stdio.h>#include<stdio.h>#include<malloc.h>typedefstructProcessNode/进程结点的基本结构charname;/进程名intservice_time;服务时间intarrive_time;到达时间intpriority;/优先级structFCFS_time/先到先服务intfinish_time;完成时间intturnaround_time;周转时间floatweigtharound_time;/带权周转时间FCFS_time;structSJF_time短作业优先intfin
2、ish_time;intturnaround_time;floatweigtharound_time;intflag;SJF_time;structRR_time/时间片轮转的结点intfinish_time;intturnaround_time;floatweigtharound_time;intflag_time;赋值为进程的服务时间,为。则进程完成RR_time;structPri_time/优先权非抢占式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();/读入进程的基本信息dop=head->next;printf("n"
4、);输出初始化后的进程基本信息printf("*进程初始彳t息输出*n");/printf("n");printf("进程名称”);printf("到达时间");printf("服务时间");printf("优先级");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");/输出进程的调用选择项printf("n");printf("1、FCFS-冼至U先服务n");printf("2、SJF-短作业优先n");printf("3、RR-时间片轮转n");printf("4、Pri优先权调度n");printf("5、退出n&
6、quot;);printf("n");printf("*n");printf("n");printf(“请在15之间选择:");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()/进程读入函数(inti;intnum;/ProcessNode;Linklistpro;Linklistp;Linklisthead;printf("n");printf("坟*进程调度算法*n");printf("n");printf("请输入进程的个数:");scanf("%d",&num);printf("
8、;n");printf("*初始化信息*n");printf("n");head=(Linklist)malloc(sizeof(ProcessNode)佚结点head->next=NULL;p=head;for(i=1;i<=num;i+)(pro=(Linklist)malloc(sizeof(ProcessNode);创建进程结点printf("输入第%d个进程信息:n”,i);printf("请输入进程名:");fflush(stdin);scanf("%c",&pr
9、o->name);printf("到达时间:");scanf("%d”,&pro->arrive_time);printf("服务时间:");scanf("%d",&pro->service_time);printf("优先级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则到先服务算法函数Linklistp;Linklistq;指向前一进程p=head->next;while(p)初始化进程的完成时间、周转时间、带权周转时间,初值均赋为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;/避免第个进程至ij达时间不为0while(p)if(p->arrive_time<=q->FCFS_time.finish_time)/T一进程已至ij达,在等待中p->FCFS_time.finish_time=(p->service_time)+(q->FCFS_time.finish_time)服务时间p->FCFS_time.turnaround_time=(p->FCFS_time.finish_time)-(p->arrive_
12、time);周转时间p->FCFS_time.weigtharound_time=(float)(p->FCFS_time.turnaround_time)/(p->service_time);带权周转时间elsep->FCFS_time.finish_time=p->service_time+p->arrive_time;/艮务时间p->FCFS_time.turnaround_time=(p->FCFS_time.finish_time)-(p->arrive_time);周转时间p->FCFS_time.weigtharound
13、_time=(float)(p->FCFS_time.turnaround_time)/(p->service_time);带权周转时间q=p;p=p->next;p=head->next;printf("*到先服务调度后的进程信息printf("n");printf("进程名称”);printf("到达时间");printf("服务时间");printf("优先级");printf("完成时间");printf("周转时间”);printf
14、("带权周转时间”);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)短作业优先算法(Linklistp,r;Linklistq;指向前一进程结点intnum=0;记录进程个数intadd_flag=0;进程完成
16、服务个数intservice_time_min;intarrive_time;intk;p=head->next;首元结点while(p)初始化进程的完成时间、周转时间、带权周转时间,初值均赋为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;将创建的进程队列变为循环队列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);倜转时间p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/滞权周转时间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)寻找最短的作业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;指针指向最短作业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);周转时间p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/带权周转时间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)寻找最短的作业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、业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);周转时间p->SJF_time.weigtharound_time=(float)(p->SJF_time.turnaround_time)/(p->service_time);/带权周转时间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-)/断开循环队歹U(q=p;p=p->next;)q->next=NULL;p=head->next;指向链首,输出短作业调度后的进程信息printf("n");printf('坟*SJF*n");printf("n");printf("进程名称”);printf("到达时间");printf("服务时间");pr
24、intf("优先级");printf("完成时间");printf("周转时间”);printf("带权周转时间");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)时间片轮转算法
26、(Linklistq;指向前一进程结点Linklistp;intq_time;时间片大小intnum=0;记录进程个数intadd_flag=0;进程完成服务个数printf("请输入时间片的大小:”);scanf("%d",&q_time);p=head->next;while(p)初始化进程的完成时间、周转时间、带权周转时间,初值均赋为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;将创建的进程队歹U变为循环队歹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)服务时间大于时间片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)有进程等待q=p;p=p->next;else/当前进程未完成,无进程等待,指针不向后移q=p;elseif(p->RR_time.flag_time)=0)/进程已经完成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);周转时间p->RR_time.weigtharound_time=(float)(p->RR_time.turnaround_time)/(p->service_time);带权周转时间if(p->next->arrive_time)<(p->RR_time.finish_time)有进程等待q=p;p=p->next;else/当前进程完成,无进程等待,指针向后移/q=p;q->RR_time.finish_time=p->next->arrive_time;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 个人信用贷款第三方担保合同样本
- 云存储硬盘空间租用合同协议
- 上市公司技术合作合同模板
- 个人房屋抵押贷款合同范本
- 临时用工安全免责合同协议
- 个人理财规划合同书
- 专业版办公室装修合同模板
- 二手汽车购销合同范本
- 云计算资源租赁与服务外包合同
- 个人住房贷款担保合同样本
- 中考记叙文阅读
- 《计算机应用基础》-Excel-考试复习题库(含答案)
- 产科沟通模板
- 2023-2024学年四川省成都市小学数学一年级下册期末提升试题
- GB/T 7462-1994表面活性剂发泡力的测定改进Ross-Miles法
- GB/T 2934-2007联运通用平托盘主要尺寸及公差
- GB/T 21709.13-2013针灸技术操作规范第13部分:芒针
- 2022年青岛职业技术学院单招语文考试试题及答案解析
- 急诊科进修汇报课件
- 一年级家访记录表(常用)
- 信息技术基础ppt课件(完整版)
评论
0/150
提交评论