课程设计要求:
1.至少有四种的作业
调度算法。
2.根据不同的调度算法算出每个作业的周转时间和带权周转时间,并通过一组作业算出系统的平均周转时间和平均带权周转时间,比较各种算法的优缺点。
3.设计一个较实用的用户界面,以便选择不同的作业调度算法。
- 概要设计
*.每个作业由一个作业控制块JCB表示,JCB包含如下信息:作业名,到达时间,开始运行时间,所需的服务时间,完成时间,周转时间,带权周转时间,作业状态,链指针等。
*.作业的状态可以是等待w,运行R,完成F三种状态之一,每个作业的最初状态总是等待w.
1). 最高优先数优先调度算法中的作业控制块PCB
#define getpcb(type)(type*)malloc(sizeof(type))
struct pcb{ String name1;
char state1; //进程状态
int super1; //优先数
int ntime1; // 运行所需时间
int rtime1; //已运行时间
int stime1; //到达时间
int btime1; //开始时间
int ftime1; //完成时间
int totime1; //周转时间
struct pcb *link;
}*ready=NULL;
pcb *p;
int countsup=0;//用于记录作业数
float ave1=0; //整组作业的带权平均周转时间
float turn1=0;//整组作业的平均周转时间
//--------------------------------------------------------------
2).简单轮转法调度算法中的作业控制块PCB
struct pcbsr{
String name;
char state; //进程状态
int ntime; // 运行所需时间
int rtime; //已运行时间
int stime; //到达时间
int btime; //开始时间
int ftime; //完成时间
int totime; //周转时间
struct pcbsr *link;
};
pcbsr *readysr=NULL; //在简单轮转法中记录队列的首指针
pcbsr *psr; //在简单轮转法中记录进程,连成链表
pcbsr *rearsr; //在简单轮转法中记录队列的尾指针
int countpsr=0; //用于记录作业数
float ave2=0; //平均带权周转时间
float turn2=0; //平均周转时间
//-------------------------------------------------------------
3).多级反馈队列调度算法中的作业控制进程块的JCB
struct pcbmul{String name;
char state; //进程状态
int super; //优先数
int ntime; // 运行所需时间
int rtime; //已运行时间
int btime; //开始时间
int ftime; //完成时间
int totime; //周转时间
struct pcbmul *link;
};
pcbmul *pmul; //在多队列反馈算法中记录进程
pcbmul *ready1=NULL; //记录第一队列首指针
pcbmul *ready2=NULL;
pcbmul *ready3=NULL;
pcbmul *ready4=NULL;
pcbmul *ready5=NULL;
pcbmul *rear1; //记录第一队列尾指针
pcbmul *rear2;
pcbmul *rear3;
pcbmul *rear4;
pcbmul *rear5;
//----------------------------------------------------------------
4).短作业优先调度算法中的作业控制块的JCB
struct pcbsf{
String name;
int ntime; // 运行所需时间
int rtime; //已运行时间
int btime; //开始时间
int ftime; //完成时间
int totime; //周转时间
struct pcbsf *link;
};
pcbsf *psf; //在短作业优先算法中记录进程
pcbsf *readysf1; //在此算法中用了两个队列此为第一队列的首指针
pcbsf *readysf2;
pcbsf *rearsf1; //第一队列尾指针
pcbsf *rearsf2;
int countsf=0; //在短作业优先中记录输入的进程数
typedef struct pcb PCB;
//---------------------------------------------------------------
5).先来先服务调度算法中的作业控制块的JCB
struct pcbfcfs{String name;
int rtime; //到达时间
int ntime; //服务时间
int btime; //开始时间
int ftime; //完成时间
int totime; //周转时间
}FCFS[50];
pcbfcfs SF[10]; //用于记录短作业优先算法中的第一个进程
int count=0; //记录输入的进程数
调度算法的流程图:


- 详细设计
以最高优先调度算法为例说明各种调度算法所包含的基本模块。
1.输入模块void _fastcall TForm1::Button1Click(TObject *Sender)
{
p=getpcb(pcb);
p->name1=Edit1->Text;
p->super1=StrToInt(Edit2->Text);
p->ntime1=StrToInt(Edit3->Text);
p->stime1=0;
p->rtime1=0;
p->state1='W';
p->link=NULL;
Memo1->Lines->Add(p->name1+"\t"+IntToStr(p->super1)+"\t"+IntToStr(p->ntime1));
Edit1->Clear();
Edit2->Clear();
Edit3->Clear();
sort();
countsup++;
Button2->Enabled=true;
}
未完!