计算机操作系统课程设计源代码《通用处理机调度演示程序源代码》 下载本文

《通用处理机调度演示程序源代码》

//短作业优先算法 #define MaxNum 100 #include #include #include struct Process_struct{

int Number; //进程编号 char Name[MaxNum]; //进程名称

int ArrivalTime; //到达时间

int ServiceTime; //开始运行时间 int FinishTime; //运行结束时间 int WholeTime; //运行时间

int run_flag; //调度标志

int order; //运行次序

double WeightWholeTime; //周转时间

double AverageWT_FCFS,AverageWT_SJF; //平均周转时间

double AverageWWT_FCFS,AverageWWT_SJF; //平均带权周转时间 }Process[MaxNum];

int N; //实际进程个数 int SJF(); //短作业优先 int SJF(){ //短作业优先算法

int temp_time=0; //当期那时间 int i=0,j;

int number_schedul,temp_counter; //进程编号,当前已执行进程个数 float run_time;

run_time=Process[i].WholeTime; j=1;

while((j

有两个进程同时到达

{

if(Process[j].WholeTime

e;

}

{ } j++;

run_time=Process[i].WholeTime; i=j;

//查找下一个被调度的进程

//对找到的下一个被调度的进程求相应的参数

number_schedul=i;

Process[number_schedul].ServiceTime=Process[number_schedul].ArrivalTim

Process[number_schedul].FinishTime=Process[number_schedul].ServiceTime

+Process[number_schedul].WholeTime;

Process[number_schedul].run_flag=1;

temp_time=Process[number_schedul].FinishTime;

Process[number_schedul].order=1;

temp_counter=1; while(temp_counter

for(j=0;j

for(j=0;j

if((Process[j].ArrivalTime<=temp_time)&&(!Process[j].run_flag))

if(Process[j].WholeTime

run_time=Process[j].WholeTime;

if((Process[j].ArrivalTime<=temp_time)&&(!Process[j].run_flag)) { }

run_time=Process[j].WholeTime; number_schedul=j; break;

}

}

number_schedul=j;

//查找下一个被调度的进程

//对找到的下一个被调度的进程求相应的参数

Process[number_schedul].ServiceTime=temp_time;

Process[number_schedul].FinishTime=Process[number_schedul].ServiceTime

+Process[number_schedul].WholeTime; }

int Pinput(); //进程参数输入 int Poutput(); //调度结果输出 int Pinput() //进程参数输入 {

int i;

printf(\请输入进程个数:\\n\scanf(\for(i=0;i

printf(\printf(\请输入一个进程:\\n\printf(\请输入进程名称:\\n\scanf(\

Process[number_schedul].run_flag=1;

temp_time=Process[number_schedul].FinishTime; temp_counter++;

Process[number_schedul].order=temp_counter;

}return 0;

printf(\请输入到达时间:\\n\

scanf(\printf(\请输入服务时间:\\n\

scanf(\

}

Process[i].ServiceTime=0; Process[i].FinishTime=0; Process[i].WeightWholeTime=0; Process[i].order=0; Process[i].run_flag=0;

}return 0;

int Poutput() //调度结果输出 {

int i;

float turn_round_time=0,f1,w=0;

printf(\ 进程名称 到达时间 运行时间 开始运行时间 结束时间 执行顺序 周

转时间 带权周转时间\\n\

printf(\ %s %d %d %d %d %d %f Process[i].WeightWholeTime=Process[i].FinishTime-Process[i].ArrivalTime;

f1=Process[i].WeightWholeTime/Process[i].WholeTime; turn_round_time+=Process[i].WeightWholeTime; w+=f1;

printf(\时刻%d :\for(i=0;i

%f\\n\viceTime,Process[i].FinishTime,Process[i].order,Process[i].WeightWholeTime,f1); }

}

printf(\printf(\return 0;