文件名称:批处理系统的作业调度模拟
文件大小:2KB
文件格式:TXT
更新时间:2013-03-28 11:51:32
作业调度
#include "stdlib.h"
typedef struct jcb
{
char name[4];
int length;
int printer;
int tape;
int runtime;
int waittime;
struct jcb *next;
}JCB;
JCB *head;
int tape,printer;
long memory;
shedule( )
{
float w,k;
JCB *p,*q,*s,*t;
do
{
p=head;
s=NULL;
q=NULL;
k=0;
while(p!=NULL)
{
if(p->length<=memory&&p->tape<=tape&&p->printer<=printer)
{
w=(float)(p->waittime)/p->runtime;
if(q==NULL||w>k)
{
k=w;
q=p;
t=s;
}
}
s=p;
p=p->next;
}
if(q!=NULL)
{
if(t==NULL)
head=head->next;
else
t->next=q->next;
memory=memory-q->length;
tape=tape-q->tape;
printer=printer-q->printer;
printf("Selects:%s\n",q->name);
}
}while(q!=NULL);
}
inital()
{
int w,k;
JCB *p,*q,*s,*t;
do
{
p=head;
s=NULL;
q=NULL;
k=0;
while(p!=NULL)
{
if(p->length<=memory&&p->tape<=tape&&p->printer<=printer)
{
w=1/(p->runtime);
if(q==NULL||w>k)
{
k=w;
q=p;
t=s;
}
}
s=p;
p=p->next;
}
if(q!=NULL)
{
if(t==NULL)
head=head->next;
else
t->next=q->next;
memory=memory-q->length;
tape=tape-q->tape;
printer=printer-q->printer;
printf("Selects:%s\n",q->name);
}
}while(q!=NULL);
}
main( )
{
int i;
int x ,n;
char name[4];
int size,tcount,pcount,wtime,rtime;
JCB *p;
memory=65536;
tape=4;
printer=2;
head=NULL;
printf("\n please inputs the quantity of JCB...\n");
scanf("%d",&n);
printf("---------------------------------------------------------------\n");
for(i=0;i