欢迎来到天天文库
浏览记录
ID:58516166
大小:52.50 KB
页数:15页
时间:2020-09-03
《操作系统进程调度C语言代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、//sun.cpp:定义控制台应用程序的入口点。//本算法包含四种调度:先到先服务,短作业优先,时间片轮转,优先级优先!#include"stdio.h"#defineN50voidmain(){voidsjp();voidfcfs();voidsjf();voidyxj();inta;while(true){printf("");printf("tt/*************************/");printf("tt/*1、先到先服务调度*/");printf("tt/*2、短作业优先调度*/");printf(
2、"tt/*3、时间片轮转调度*/");printf("tt/*4、优先级优先调度*/");printf("tt/*0、退出*/");printf("tt/*************************/");printf("t请选择菜单项:t");scanf("%d",&a);printf("");switch(a){case1:fcfs();break;case2:sjf();break;case3:sjp();break;case4:yxj();break;default:break;}if(a<0
3、&&a>4)break;}}voidsjp(){inti,j,n,min,px,sjp,time;floatsum1,sum2;boolflag=true;printf("t请输入有n个进程(050
4、
5、n<=0){printf("nt请重新输入:");scanf("%d",&n);}printf("");printf("t请输入时间片大小(06、nf("%d",&sjp);}structGzuo{intid;//进程名字intdt;//到达时刻intst;//服务时间intwct;//完成时刻intst2;//标志是否完成floatzt;//周转时间floatdczt;//带权周转时间};Gzuoa[N];for(i=0;i7、;j>=0;j--){for(i=0;ia[i+1].dt){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].st2;a[i].st2=a[i+1].st2;a[i+1].st2=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}time=a[0].dt;//printf("赋值后TIME值为:%d",time);mi8、n=0;while(min0&&a[i].dt<=time)flag=false;}for(i=0;i0){if(a[i].dt<=time){//printf("当前a[%d].st2值为:%d",i,a[i].st2);a[i].st2=a[i].st2-sjp;//printf("运算后当前a[%d].st2值为:%d",i,a[i].st2);//printf("当前TIME值为:%d",time);time=9、time+sjp;//printf("增加之后TIME值为:%d",time);if(a[i].st2<=0){a[i].wct=time+a[i].st2;a[i].zt=(float)(a[i].wct-a[i].dt);a[i].dczt=a[i].zt/a[i].st;min++;}}elseif(flag){for(i=0;i0&&a[i].dt>time){time=a[i].dt;break;}}}}}}printf("t1、按id号依次输出");printf("t2、按完成顺序依次输出10、n");printf("t请选择输出顺序:t");scanf("%d",
6、nf("%d",&sjp);}structGzuo{intid;//进程名字intdt;//到达时刻intst;//服务时间intwct;//完成时刻intst2;//标志是否完成floatzt;//周转时间floatdczt;//带权周转时间};Gzuoa[N];for(i=0;i7、;j>=0;j--){for(i=0;ia[i+1].dt){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].st2;a[i].st2=a[i+1].st2;a[i+1].st2=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}time=a[0].dt;//printf("赋值后TIME值为:%d",time);mi8、n=0;while(min0&&a[i].dt<=time)flag=false;}for(i=0;i0){if(a[i].dt<=time){//printf("当前a[%d].st2值为:%d",i,a[i].st2);a[i].st2=a[i].st2-sjp;//printf("运算后当前a[%d].st2值为:%d",i,a[i].st2);//printf("当前TIME值为:%d",time);time=9、time+sjp;//printf("增加之后TIME值为:%d",time);if(a[i].st2<=0){a[i].wct=time+a[i].st2;a[i].zt=(float)(a[i].wct-a[i].dt);a[i].dczt=a[i].zt/a[i].st;min++;}}elseif(flag){for(i=0;i0&&a[i].dt>time){time=a[i].dt;break;}}}}}}printf("t1、按id号依次输出");printf("t2、按完成顺序依次输出10、n");printf("t请选择输出顺序:t");scanf("%d",
7、;j>=0;j--){for(i=0;ia[i+1].dt){min=a[i].dt;a[i].dt=a[i+1].dt;a[i+1].dt=min;min=a[i].st;a[i].st=a[i+1].st;a[i+1].st=min;min=a[i].st2;a[i].st2=a[i+1].st2;a[i+1].st2=min;min=a[i].id;a[i].id=a[i+1].id;a[i+1].id=min;}}}time=a[0].dt;//printf("赋值后TIME值为:%d",time);mi
8、n=0;while(min0&&a[i].dt<=time)flag=false;}for(i=0;i0){if(a[i].dt<=time){//printf("当前a[%d].st2值为:%d",i,a[i].st2);a[i].st2=a[i].st2-sjp;//printf("运算后当前a[%d].st2值为:%d",i,a[i].st2);//printf("当前TIME值为:%d",time);time=
9、time+sjp;//printf("增加之后TIME值为:%d",time);if(a[i].st2<=0){a[i].wct=time+a[i].st2;a[i].zt=(float)(a[i].wct-a[i].dt);a[i].dczt=a[i].zt/a[i].st;min++;}}elseif(flag){for(i=0;i0&&a[i].dt>time){time=a[i].dt;break;}}}}}}printf("t1、按id号依次输出");printf("t2、按完成顺序依次输出
10、n");printf("t请选择输出顺序:t");scanf("%d",
此文档下载收益归作者所有