批处理系统的作业调度模拟

时间:2013-03-28 11:51:32
【文件属性】:
文件名称:批处理系统的作业调度模拟
文件大小: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;iname,name); p->length=size; p->printer=pcount; p->tape=tcount; p->runtime=rtime; p->waittime=wtime; p->next=head; head=p;} printf("---------------------------------------------------------------\n" "[1]_The response compares first the algorithm\n" "[2]_Short work first algorithm\n" "---------------------------------------------------------------\n" "please chose [1]or[2]...\n"); scanf("%d",&x); switch (x){ case 1:shedule(); printf("---------------------------------------------------------------\n"); break; case 2:inital(); printf("---------------------------------------------------------------\n"); break; default:printf("\n error..please try again!\n");main(); } }

网友评论