操作系统进程调度C语言代码.docx
- 文档编号:11881646
- 上传时间:2023-04-08
- 格式:DOCX
- 页数:20
- 大小:17.45KB
操作系统进程调度C语言代码.docx
《操作系统进程调度C语言代码.docx》由会员分享,可在线阅读,更多相关《操作系统进程调度C语言代码.docx(20页珍藏版)》请在冰豆网上搜索。
操作系统进程调度C语言代码
d=i+1;
printf("\t到达时间:
");
scanf("%d",&a[i].dt);
printf("\t服务时间:
");
scanf("%d",&a[i].st);
a[i].st2=a[i].st;
printf("\n");
}
for(j=n-1;j>=0;j--)
{
for(i=0;i { if(a[i].dt>a[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; t2>0&&a[i].dt<=time) flag=false; } for(i=0;i { if(a[i].st2>0) { if(a[i].dt<=time) { t2值为: %d\n",i,a[i].st2); a[i].st2=a[i].st2-sjp; t2值为: %d\n",i,a[i].st2); t2<=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;i { if(a[i].st2>0&&a[i].dt>time) { time=a[i].dt; break; } } } } } } printf("\t1、按id号依次输出\n"); printf("\t2、按完成顺序依次输出\n"); printf("\n\t请选择输出顺序: \t"); scanf("%d",&px); printf("\nid: 到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间\n"); sum1=0; sum2=0; switch(px) { case2: { for(i=0;i { printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i].zt,a[i].dczt); sum1+=a[i].zt; sum2+=a[i].dczt; } printf("\n平均周转时间: %.2f\n",sum1/n); printf("\n平均带权周转时间: %.2f\n\n",sum2/n); break; } case1: { for(j=0;j { for(i=0;i if(a[i].id==j+1) { printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i].zt,a[i].dczt); sum1+=a[i].zt; sum2+=a[i].dczt; } } printf("\n平均周转时间: %.2f\n",sum1/n); printf("\n平均带权周转时间: %.2f\n\n",sum2/n); break; } default: break; } } voidfcfs() { inti,j,n,min,px; floatsum1,sum2; printf("\t请输入有n个进程(0 \t"); scanf("%d",&n); while(n>50||n<=0) { printf("n\t请重新输入: "); scanf("%d",&n); } printf("\n\n"); structGzuo{ intid;d=i+1; printf("\t到达时间: "); scanf("%d",&a[i].dt); printf("\t服务时间: "); scanf("%d",&a[i].st); printf("\n"); } for(j=n-1;j>=0;j--) { for(i=0;i { if(a[i].dt>a[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].id; a[i].id=a[i+1].id; a[i+1].id=min; } } } a[0].wct=a[0].st+a[0].dt; a[0].zt=(float)a[0].st; a[0].dczt=a[0].zt/a[0].st; for(i=1;i { if(a[i].dt>a[i-1].wct) { a[i].wct=a[i].dt+a[i].st; a[i].zt=(float)a[i].st; a[i].dczt=a[i].zt/a[i].st; } else { a[i].wct=a[i-1].wct+a[i].st; a[i].zt=(float)(a[i].wct-a[i].dt); a[i].dczt=a[i].zt/a[i].st; } } printf("\t1、按id号依次输出\n"); printf("\t2、按完成顺序依次输出\n"); printf("\n\t请选择输出顺序: \t"); scanf("%d",&px); printf("\nid: 到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间\n"); sum1=0; sum2=0; switch(px) { case2: { for(i=0;i { printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i].zt,a[i].dczt); sum1+=a[i].zt; sum2+=a[i].dczt; } printf("\n平均周转时间: %.2f\n",sum1/n); printf("\n平均带权周转时间: %.2f\n\n",sum2/n); break; } case1: { for(j=0;j { for(i=0;i if(a[i].id==j+1) { printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i].zt,a[i].dczt); sum1+=a[i].zt; sum2+=a[i].dczt; } } printf("\n平均周转时间: %.2f\n",sum1/n); printf("\n平均带权周转时间: %.2f\n\n",sum2/n); break; } default: break; } } voidsjf() { inti,j,n,min,px; intb=0,z; floatsum1,sum2; printf("\n\t\t请输入有n个进程(0 \t"); scanf("%d/n",&n); while(n>50||n<=0) { printf("n\t请重新输入: "); scanf("%d",&n); } printf("\n"); structGzuo{ intid;d=i+1; printf("\t到达时间: "); scanf("%d",&a[i].dt); printf("\t服务时间: "); scanf("%d",&a[i].st); printf("\n"); } min=a[0].dt; for(j=n-1;j>=0;j--) { for(i=0;i { if(a[i].dt>a[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].id; a[i].id=a[i+1].id; a[i+1].id=min; } if(a[i].dt==a[i+1].dt&&a[i].st>a[i+1].st) { 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].id; a[i].id=a[i+1].id; a[i+1].id=min; } } } a[0].wct=a[0].st+a[0].dt; a[0].zt=(float)a[0].st; a[0].dczt=a[0].zt/a[0].st; for(i=1;i { if(a[i].dt>a[0].wct); elseb=b+1; } for(j=b-1;j>=1;j--) { for(i=1;i { if(a[i].st>a[i+1].st) { 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].id; a[i].id=a[i+1].id; a[i+1].id=min; } } } for(i=1;i { if(a[i].dt>a[i-1].wct) { a[i].wct=a[i].dt+a[i].st; a[i].zt=(float)a[i].st; a[i].dczt=a[i].zt/a[i].st; } else { a[i].wct=a[i-1].wct+a[i].st; a[i].zt=(float)(a[i].wct-a[i].dt); a[i].dczt=a[i].zt/a[i].st; } for(j=i+1,b=j;j { if(a[j].dt>a[i].wct); elseb=b+1; } for(j=b-1;j>=i;j--) { for(z=i;z { if(a[z].st>a[z+1].st) { min=a[z].dt; a[z].dt=a[z+1].dt; a[z+1].dt=min; min=a[z].st; a[z].st=a[z+1].st; a[z+1].st=min; min=a[i].id; a[i].id=a[i+1].id; a[i+1].id=min; } } } } printf("\n\t请选择输出顺序\n"); printf("\t1、按id号依次输出\n"); printf("\t2、按完成顺序依次输出\n"); scanf("%d",&px); printf("\nid: 到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间\n"); sum1=0; sum2=0; switch(px) { case2: { for(i=0;i { printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i].zt,a[i].dczt); sum1+=a[i].zt; sum2+=a[i].dczt; } printf("\n平均周转时间: %.2f\n",sum1/n); printf("\n平均带权周转时间: %.2f\n\n",sum2/n); break; } case1: { for(j=0;j {for(i=0;i if(a[i].id==j+1) { printf("%d: %d\t\t%d\t\t%d\t\t%.0f\t\t%.2f\n",a[i].id,a[i].dt,a[i].st,a[i].wct,a[i].zt,a[i].dczt); sum1+=a[i].zt; sum2+=a[i].dczt; } } printf("\n平均周转时间: %.2f\n",sum1/n); printf("\n平均带权周转时间: %.2f\n\n",sum2/n); break; } default: break; } } voidyxj() { inti,j,n,min,px; intb=0,z; floatsum1,sum2; printf("\n\t\t请输入有n个进程(0 \t"); scanf("%d/n",&n); while(n>50||n<=0) { printf("n\t请重新输入: "); scanf("%d",&n); } printf("\n"); structGzuo{ intid;d=i+1; printf("\t到达时间: "); scanf("%d",&a[i].dt); printf("\t服务时间: "); scanf("%d",&a[i].st); printf("\t优先级: "); scanf("%d",&a[i].yxj); printf("\n"); } min=a[0].dt; for(j=n-1;j>=0;j--) { for(i=0;i { if(a[i].dt>a[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].id; a[i].id=a[i+1].id; a[i+1].id=min; min=a[i].yxj; a[i].yxj=a[i+1].yxj; a[i+1].yxj=min; } if(a[i].dt==a[i+1].dt&&a[i].yxj { 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].id; a[i].id=a[i+1].id; a[i+1].id=min; min=a[i].yxj; a[i].yxj=a[i+1].yxj; a[i+1].yxj=min; } } } a[0].wct=a[0].st+a[0].dt; a[0].zt=(float)a[0].st; a[0].dczt=a[0].zt/a[0].st; for(i=1;i { if(a[i].dt>a[0].wct); elseb++; } for(j=b-1;j>=1;j--) {
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 进程 调度 语言 代码
![提示](https://static.bdocx.com/images/bang_tan.gif)