c语言课程设计处理机低级调度模拟系统Word格式.docx

上传人:b****5 文档编号:18343383 上传时间:2022-12-15 格式:DOCX 页数:24 大小:459.71KB
下载 相关 举报
c语言课程设计处理机低级调度模拟系统Word格式.docx_第1页
第1页 / 共24页
c语言课程设计处理机低级调度模拟系统Word格式.docx_第2页
第2页 / 共24页
c语言课程设计处理机低级调度模拟系统Word格式.docx_第3页
第3页 / 共24页
c语言课程设计处理机低级调度模拟系统Word格式.docx_第4页
第4页 / 共24页
c语言课程设计处理机低级调度模拟系统Word格式.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

c语言课程设计处理机低级调度模拟系统Word格式.docx

《c语言课程设计处理机低级调度模拟系统Word格式.docx》由会员分享,可在线阅读,更多相关《c语言课程设计处理机低级调度模拟系统Word格式.docx(24页珍藏版)》请在冰豆网上搜索。

c语言课程设计处理机低级调度模拟系统Word格式.docx

1、按照给出的题目内容

(1)完成系统数据结构设计与实现、系统算法设计与实现、系统模块设计与实现、系统总体的设计与实现。

(2)系统需要一个简单操作界面,例如:

===========================

1.先来先服务调度

2.多级反馈队列调度

3.退出

(按数字1、2、3、,选择操作)

(3)对每种调度算法都要求输出每个进程(进程数不少于5)开始运行时刻、完成时刻、周转时间,以及这组进程的平均周转时间。

(4)画出每种调度算法流程图。

1.先来先服务调度:

2.多级反馈队列调度:

四:

课程设计过程:

1.系统中所使用的数据结构及说明

……..数据结构的定义…………..

定义进程控制块PCB

structPCB{

charname[10];

//进程名字

floatarrivetime;

//进程到达时间

floatservicetime;

//进程服务时间

floatsuper;

//响应比

floatstarttime;

//开始运行时间

floatfinishtime;

//完成时间

floatTurnaroundTime;

//周转时间

charstate;

//进程的状态,W就绪态,R执行态,F完成态

intprio;

//优先级

intround;

//时间片

intcputime;

//cpu时间

intneedtime;

//进程运行时间

intcount;

//计数器

structPCB*next;

}*ready=NULL,*p,*q;

定义就绪队列:

typedefstructQueue//多级就绪队列节点信息

{

PCB*LinkPCB;

//就绪队列中的进程队列指针

//本就绪队列的优先级

//本就绪队列所分配的时间片

structQueue*next;

//指向下一个就绪队列的链表指针

}ReadyQueue;

2.系统功能结构

本系统是处理机低级调度模拟系统,主要通过模拟来实现处理机调度,调度方式有先来先服务调度(FCFS)、短进程优先调度(SJF)、高响应比优先调度(HRN)、多级反馈队列调度(FB)四种调度方式。

系统运行过程如下:

输入进程个数,输入进程详细信息,通过简单操作界面来选择调度方式,调度的过程和结果,重新选择调度方式或者选择结束。

3.程序清单及描述

#defineNULL0

#include<

stdio.h>

stdlib.h>

conio.h>

string.h>

windows.h>

PCBa[100];

intN;

voidcreateProcess(PCB*p)//创建进程函数

inti;

printf("

输入进程名&

到达时间&

服务时间:

\n例如:

a0100\n"

);

for(i=0;

i<

=N-1;

i++)

{

printf("

输入第%d个进程的信息:

\n"

i+1);

scanf("

%s%f%f"

&

p[i].name,&

p[i].arrivetime,&

p[i].servicetime);

}

}

voidsort(PCB*p,intN)//到达时间排序

{

for(inti=0;

for(intj=0;

j<

=i;

j++)

if(p[i].arrivetime<

p[j].arrivetime)

PCBtemp;

temp=p[i];

p[i]=p[j];

p[j]=temp;

voidrunning(PCB*p,floatarrivetime,floatservicetime,floatstarttime,floatfinishtime,float&

TurnaroundTime,intN)//计算进程时间

intk;

for(k=0;

k<

k++)

if(k==0)

{

p[k].starttime=p[k].arrivetime;

p[k].finishtime=p[k].arrivetime+p[k].servicetime;

}

else

{

p[k].starttime=p[k-1].finishtime;

p[k].finishtime=p[k-1].finishtime+p[k].servicetime;

}

p[k].TurnaroundTime=p[k].finishtime-p[k].arrivetime;

voidprint(PCB*p,floatarrivetime,floatservicetime,floatstarttime,floatfinishtime,floatTurnaroundTime,intN)//进程输出各种时间

{intk;

运行次序:

"

%s"

p[0].name);

for(k=1;

N;

-->

p[k].name);

\n进程的信息:

\n进程名\t到达\t服务\t开始\t完成\t周转\n"

%s\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t%-.2f\t\n"

p[k].name,p[k].arrivetime,p[k].servicetime,p[k].starttime,p[k].finishtime,p[k].TurnaroundTime);

}

voidfcfs(PCB*p)//先来先服务调度算法

system("

cls"

请输入作业数:

scanf("

%d"

N);

while(N<

5)//进程小于5的话,重新选择输入

system("

\n\7\7作业数小于5,重新输入:

createProcess(a);

floatarrivetime=0,servicetime=0,starttime=0,finishtime=0,TurnaroundTime=0;

sort(p,N);

//排序

running(p,arrivetime,servicetime,starttime,finishtime,TurnaroundTime,N);

//模拟运行

print(p,arrivetime,servicetime,starttime,finishtime,TurnaroundTime,N);

//打印输入结果

PCB*run=NULL,*finish=NULL;

//定义三个队列,就绪队列,执行队列和完成队列

ReadyQueue*Head=NULL;

//定义第一个就绪队列

intnum;

//进程个数

intReadyNum;

//就绪队列个数

voidOutput();

//进程信息输出函数

voidInsertFinish(PCB*in);

//将进程插入到完成队列尾部

voidInsertPrio(ReadyQueue*in);

//创建就绪队列,规定优先数越小,优先级越低

voidPrioCreate();

//创建就绪队列输入函数

voidGetFirst(ReadyQueue*queue);

//取得某一个就绪队列中的队头进程

voidInsertLast(PCB*in,ReadyQueue*queue);

//将进程插入到就绪队列尾部

voidProcessCreate();

//进程创建函数

voidRoundRun(ReadyQueue*timechip);

//时间片轮转调度算法

voidMultiDispatch();

//多级调度算法,每次执行一个时间片

voidOutput()//进程信息输出函数

ReadyQueue*print=Head;

PCB*p;

进程名\t优先级\t轮数\tcpu时间\t需要时间\t进程状态\t计数器\n"

while(print)

{

if(print->

LinkPCB!

=NULL)

p=print->

LinkPCB;

while(p)

{

printf("

%s\t%d\t%d\t%d\t%d\t\t%c\t\t%d\n"

p->

name,p->

prio,p->

round,p->

cputime,p->

needtime,p->

state,p->

count);

p=p->

next;

}

print=print->

p=finish;

while(p!

=NULL)

p=p->

p=run;

p=p->

}

voidInsertFinish(PCB*in)//将进程插入到完成队列尾部

PCB*fst;

fst=finish;

if(finish==NULL)

in->

next=finish;

finish=in;

else

while(fst->

next!

fst=fst->

in->

next=fst->

fst->

next=in;

voidInsertPrio(ReadyQueue*in)//创建就绪队列,规定优先数越小,优先级越低

ReadyQueue*fst,*nxt;

fst=nxt=Head;

if(Head==NULL)//没有队列,则为第一个元素

in->

next=Head;

Head=in;

else//查到合适的位置进行插入

if(in->

prio>

=fst->

prio)//比第一个还要大,则插入到队头

in->

Head=in;

else

while(fst->

=NULL)//移动指针查找第一个别它小的元素的位置进行插入

nxt=fst;

fst=fst->

if(fst->

next==NULL)//已经搜索到队尾,则其优先级数最小,将其插入到队尾即可

in->

fst->

else//入到队列中

nxt=in;

next=fst;

voidPrioCreate()//创建就绪队列输入函数

ReadyQueue*tmp;

输入就绪队列的个数:

ReadyNum);

输入每个就绪队列的CPU时间片:

(一次行输完所有,再按回车结束,如:

123)\n"

for(i=0;

i<

ReadyNum;

i++)

if((tmp=(ReadyQueue*)malloc(sizeof(ReadyQueue)))==NULL)

perror("

malloc"

exit

(1);

(tmp->

round));

//输入此就绪队列中给每个进程所分配的CPU时间片

tmp->

prio=50-tmp->

round;

//置其优先级,时间片越高,其优先级越低

LinkPCB=NULL;

//初始化其连接的进程队列为空

next=NULL;

InsertPrio(tmp);

//照优先级从高到低,建立多个就绪队列

voidGetFirst(ReadyQueue*queue)//取得某一个就绪队列中的队头进程

run=queue->

if(queue->

run->

state='

R'

;

queue->

LinkPCB=queue->

LinkPCB->

voidInsertLast(PCB*in,ReadyQueue*queue)//将进程插入到就绪队列尾部

fst=queue->

if(queue->

LinkPCB==NULL)

next=queue->

queue->

LinkPCB=in;

voidProcessCreate()//针对多级反馈队列算法的进程创建函数

PCB*tmp;

num);

if(num<

5)

ProcessCreate();

输入进程名字和进程所需时间:

(一次性输完,再按回车结束如:

a1b2c3d4e5)\n"

num;

if((tmp=(PCB*)malloc(sizeof(PCB)))==NULL)

tmp->

name);

getchar();

needtime));

cputime=0;

state='

W'

needtime;

//置其优先级,需要的时间越多,优先级越低

round=Head->

count=0;

InsertLast(tmp,Head);

//照优先级从高到低,插入到就绪队列

voidRoundRun(ReadyQueue*timechip)//时间片轮转调度算法

intflag=1;

GetFirst(timechip);

while(run!

while(flag)

run->

count++;

cputime++;

needtime--;

if(run->

needtime==0)

run->

F'

InsertFinish(run);

flag=0;

elseif(run->

count==timechip->

round)//间片用完

run->

//数器清零,为下次做准备

InsertLast(run,timechip);

flag=1;

GetFirst(timechip);

voidMultiDispatch()//多级调度算法,每次执行一个时间片

intk=0;

您选择的是多级反馈队列算法\n"

PrioCreate();

//建就绪队列

ProcessCreate();

//创建就绪进程队列

ReadyQueue*point;

point=Head;

GetFirst(point);

Output();

if(Head->

LinkPCB!

point=Head;

run->

if(run->

needtime==0)//程执行完毕

count==run->

if(point->

next!

{

run->

round=point->

next->

//置其时间片是下一个就绪队列的时间片

InsertLast(run,point->

next);

//进程插入到下一个就绪队列中

flag=0;

}

else

RoundRun(point);

//果为最后一

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 图表模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1