当前位置:文档之家› 华东交通大学操作系统实验二作业调度实验(含代码)

华东交通大学操作系统实验二作业调度实验(含代码)


选择 3 进入“响应比高者优先算法”作业调度:
float super;
//作业的响应比
int finishtime;
//作业完成时间
float cycletime;
//作业周转时间
float cltime;
//作业带权周转时间
char state;
//作业状态
struct jcb *next;
//结构体指针
}*ready=NULL,*p,*q;
typedef struct jcb JCB;
void inize()
//初始化界面
{
printf("\n\n\t\t*********************************************\t\t\n");
printf("\t\t\t\t 单道批处理作业调度系统\n");
printf("\t\t*********************************************\t\t\n");
printf("\n\n\n\t\t\t1.先来先服务算法"); printf("\n\t\t\t2.最短作业优先算法"); printf("\n\t\t\t3.响应比高者优先算法"); printf("\n\t\t\t0.退出程序"); printf("\n\n\t\t\t\t 选择算法:"); scanf("%d",&m); switch(m) {
times+=p->needtime;
p->state='F';
printf("\n%s 作业已完成!\n 请按任意键继续...\n",p->name);
free(p);
//释放运行后的作业
getch();
}
void super()
//计算队列中作业的高响应比
{
JCB *padv;
padv=ready;
case 1: fcfs(m); getch(); system("cls");
mune();
break;
case 2:
sjf(m);
getch();
system("cls");
mune();
break;
case 3:
hrn(m);
getch();
system("cls");
mune();
break;
if(iden)
{
min=p;iden=0;
}
else if(p->super>min->super) min=p;
p=p->next;
}while(p!=NULL);
if(iden)
{
i--;times++;
if(times>1000)
{printf("\nruntime is too long...error...");getch();}
}
void fcfs(int m) //先来先服务算法
{
int i,iden;
system("cls");
inital();
for(i=0;i<n;i++)
{
p=ready;iden=1;
do{
if(p->state=='W'&&p->reachtime<=times) iden=0;
if(iden)p=p->next;
实验二 作业调度实验
一 . 目的要求:
用高级语言编写和调试作业调度的模拟程序,以加深对作业调度算法的理 解。
二、实验要求: 为单道批处理系统设计一个作业调度程序。
由于在单道批处理系统中,作业一投入运行,它就占有计算机的一切资源直 到作业完成为止,因此调度作业时不必考虑它所需要的资源是否得到满足、它所 占用的 CPU 时限等因素。
每个作业完成后要打印该作业的开始运行时刻、完成时刻、周转时间和带权
周转时间,这一组作业完成后要计算并打印这组作业的平均周转时间、带权平均
周转时间。
源代码:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define getpch(type) (type*)malloc(sizeof(type))
}
else
{
running(min,m);
//调用 running()函数
}
} //for
final();
//调用 running()函数
}
void sjf(int m)
// 最短作业优先算法
{
JCB *min;
int i,iden;
system("cls");
inital();
for(i=0;i<n;i++)
}while(p!=NULL&&iden) ;
if(iden)
{
i--;
printf("\n 没有满足要求的进程,需等待");
times++;
if(times>100){printf("\n 时间过长");getch();}
}
else{
running(p,m); //调用 running()函数
}
}
{
p=min=ready;iden=1;
do{
if(p->state=='W'&&p->reachtime<=times)
if(iden){
min=p;iden=0;
}
else if(p->needtime<min->needtime) min=p;
p=p->next;
}while(p!=NULL) ;
printf("\n\n\n\t\t\t\t\t09 软件+电子商务 2 班\n");
printf("\t\t\t\t\t\t 黄才旺\n\n");
printf("\n\n\n\t\t 请按任意键进入主菜单:");
getch();
}
void inital() //建立作业控制块队列,先将其排成先来先服务的模式队列
printf(" %f \t",q->cycletime);
printf(" %f\t",q->cltime);
getch();
}
}
void running(JCB *p,int m)
//运行作业
{
if(p==ready)
//先将要运行的作业从队列中分离出来
{
ready=p->next;
p->next=NULL;
}
void final()源自//最后打印作业的平均周转时间,平均带权周转时间
{
float s,t;
t=T1/n;
s=T2/n;
getch();
printf("\n\n 作业已经全部完成!");
printf("\n%d 个作业的平均周转时间是:%f",n,t);
printf("\n%d 个作业的平均带权周转时间是:%f\n\n\n",n,s);
printf("
%d \t",q->finishtime);
printf(" %f \t",q->cycletime);
printf(" %f\t",q->cltime);
printf(" %f\n",q->super);
getch();
}
else
// 显示先来先服务,最短作业优先算法调度后作业的运行
p->cycletime=(float)(p->finishtime-p->reachtime);
p->cltime=(float)(p->cycletime/p->needtime);
T1+=p->cycletime;
T2+=p->cltime;
disp(p,m);
//调用 disp()函数,显示作业运行情况
{
int i;
printf("\n 输入作业数:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p=getpch(JCB);
printf("\n 输入作业名:");
scanf("%s",p->name);
getch();
p->reachtime=i;
printf("作业默认到达时间:%d",i);
}
void hrn(int m)
//高响应比算法
{
JCB *min;
int i,iden;
system("cls");
inital();
for(i=0;i<n;i++)
{
p=min=ready;iden=1;
相关主题