进程调度
hello 我是橘子
我觉得我写代码特别啰嗦,就是很尴尬,希望大家可以原谅
●基本要求:在1、2、3阶段实验基础上实现按先来先服务FCFS、短作业优先SJF以及时间片轮转算法调度进程的模拟过程。
●参考学时:9学时
●实验提示:
1、程序开始运行时选择调度算法,创建进程时输入进程所需服务时间以及到达时间。可参考如下数据结构:
struct PCB{
char name[10];
int size;
int arrival_time; //到达时间
int burst_time; //服务时间
int finished_time; //结束运行时间
int runned_time; //已运行时间
struct PCB*next;
};
struct PCB *ready,*blocked,*running,*finished;
其中,finished队列是已运行结束的进程队列,便于统计各项时间数据。
2、根据当前所设定调度算法,连续调度所有进程,并计算每个进程的周转时间和带权周转时间、所有进程的平均周转时间和平均带权周转时间。
3、调度时应适当输出调度过程中各进程状态队列的变化情况以及进程的已执行时间、还需服务时间(针对时间片轮转算法)。
4、*完成银行家算法的实现。
●评分标准(满分15分):
要求必须完成以下几个方面的内容(10-12分):
●在第1-3部分基础上扩展;
●支持FCFS、短作业优先以及时间片调度算法。
也可实现如下扩充要求(3-5分):
●能够较方便地查看调度过程及平均周转时间、平均带权周转时间;
*支持优先权调度算法与其它算法相结合的调度模式
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<fstream>
using namespace std;
typedef struct PCB{
string name;
int size1;
int arrival_time;//到达时间
int burst_time;//服务时间
int finished_time;//结束运行时间
int runned_time;//已运行时间
double zhouzhuan_time; //周转时间
double daiquan_time;// 带权周转时间
int youxianji;//优先级
struct PCB *next;
}PCB,*NODE;
struct yinhang// 银行家的结构体
{
char name1[20];
int A;//总共需要的
int B;
int C;
int allocationA;//已分配的
int allocationB;
int allocationC;
int needA;//还需要的
int needB;
int needC;
int finish;
};
int availableA=0;
int availableB=0;
int availableC=0;
int cpyA=0;
int cpyB=0;
int cpyC=0;
struct yinhang yhj[20];
int yh;//角标
NODE ready,blocked,running,finished;
void creat1()
{
string name;
int size1,time1,time2,you;
NODE q1,q2;
cout<<"请输入名字:";
cin>>name;
// cout<<"请输入大小:";
// cin>>size1;
cout<<"请输入优先级(优先级越小就先运行):";
cin>>you;
cout<<"请输入到达时间:";
cin>>time1;
cout<<"请输入服务时间:";
cin>>time2;
q1=new PCB;
q1->name=name;
// q1->size1=size1;
q1->arrival_time=time1;
q1->burst_time=time2;
q1->finished_time=0;
q1->runned_time=0;
q1->youxianji=you;
q1->next=NULL;
q2=ready;//插入就绪队列中
while(q2->next!=NULL)
q2=q2->next;
q2->next=q1;
q1->next=NULL;
}
void addpcb(NODE head,NODE node)//添加进程
{
if(node!=NULL)
{
NODE tmp=head;
while(tmp->next!=NULL)
tmp=tmp->next;
tmp->next=node;
node->next=NULL;
}
}
void create_process(string name,int arrtime,int bursttime, int youxianji)
{
int i;
NODE tmp;
tmp=new PCB;
tmp->name=name;
tmp->arrival_time=arrtime;
tmp->burst_time=bursttime;
tmp->youxianji=youxianji;
tmp->finished_time=0;
tmp->runned_time=0;
addpcb(ready,tmp);
}
void show()
{
NODE q1;
cout<<"ready:";
q1=ready;
while(q1->next!=NULL)
{
cout<<q1->next->name<<" ";
q1=q1->next;
}
cout<<endl;
NODE q2;
cout<<"running:";
q2=running;
while(q2->next!=NULL)
{
cout<<q2->next->name<<" ";
q2