码迷,mamicode.com
首页 > 其他好文 > 详细

作业调度

时间:2015-05-07 10:20:08      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
#include"stdio.h"
#include"stdlib.h"
typedef struct PCB
{ char name[10];
char state;
int ArriveTime;
int StartTime;
int FinishTime;
int ServiceTime;
float WholeTime;
float WeightWholeTime;
double AverageWT_FCFS;
double AverageWWT_FCFS;
struct PCB *next;
}pcb;
double x=0,y=0;
int i;
int time;
int n;
pcb *head=NULL,*p,*q;
void run_FCFS(pcb *p1)
{
time = p1->ArriveTime > time? p1->ArriveTime:time;
p1->StartTime=time;
printf("\n时刻:%d, 当前开始运行作业%s\n\n",time,p1->name);
time+=p1->ServiceTime;
p1->state=‘T‘;
p1->FinishTime=time;
p1->WholeTime=p1->FinishTime-p1->ArriveTime;
p1->WeightWholeTime=p1->WholeTime/p1->ServiceTime;
x+=p1->WholeTime;
y+=p1->WeightWholeTime;
p1->AverageWT_FCFS=p1->WholeTime/n;
p1->AverageWWT_FCFS=p1->WeightWholeTime/n;
printf(" 到达时间/t开始时间/t服务时间/t完成时间/t周转时间/t带权周转时间/n");
printf("%6d /t%10d /t%10d /t%8d /t%10.1f /t%10.2f \n ",p1->ArriveTime,p1->StartTime,p1->ServiceTime,p1->FinishTime,p1->WholeTime,p1->WeightWholeTime);
printf("\n平均周转时间/t平均带权周转时间\n");
printf(" %10.2f /t%10.2f\n ",p1->AverageWT_FCFS,p1->AverageWWT_FCFS);
void FCFS()
{
int i;
p=head;
for(i=0;i<n;i++)
{
if(p->state==‘F‘)
{
q=p;
run_FCFS(q);
}
p=p->next;
}
}
void getInfo()
{
int num;
printf("\n进程个数:");
scanf("%d",&n);
for(num=0;num<n;num++)
{
p=(pcb *)malloc(sizeof(pcb));
printf("依次输入:\n进程名/t到达时间/t服务时间\n");
scanf("%s\t%d\t%d",&p->name,&p->ArriveTime,&p->ServiceTime);
if(head==NULL)
{head=p;q=p;time=p->ArriveTime;}
if(p->ArriveTime < time) time=p->ArriveTime;
q->next=p;
p->StartTime=0
p->FinishTime=0;
p->WholeTime=0;
p->WeightWholeTime=0;
p->next=NULL;
p->state=‘F‘;
q=p;
}
}
void main()
{
printf("先来先服务FCFS算法模拟n");
getInfo();
p=head;
FCFS();
}

 


 

 

}

 

作业调度

标签:

原文地址:http://www.cnblogs.com/xkb07/p/4483879.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!