操作系统课程设计 网络教学系统Word格式.docx

上传人:b****2 文档编号:15116430 上传时间:2022-10-27 格式:DOCX 页数:30 大小:74.40KB
下载 相关 举报
操作系统课程设计 网络教学系统Word格式.docx_第1页
第1页 / 共30页
操作系统课程设计 网络教学系统Word格式.docx_第2页
第2页 / 共30页
操作系统课程设计 网络教学系统Word格式.docx_第3页
第3页 / 共30页
操作系统课程设计 网络教学系统Word格式.docx_第4页
第4页 / 共30页
操作系统课程设计 网络教学系统Word格式.docx_第5页
第5页 / 共30页
点击查看更多>>
下载资源
资源描述

操作系统课程设计 网络教学系统Word格式.docx

《操作系统课程设计 网络教学系统Word格式.docx》由会员分享,可在线阅读,更多相关《操作系统课程设计 网络教学系统Word格式.docx(30页珍藏版)》请在冰豆网上搜索。

操作系统课程设计 网络教学系统Word格式.docx

2、设计题目

设计一个按多级队列调度算法实现处理器调度的程序。

3、设计思想

设置多个就绪队列,分别赋予不同的优先级,如逐级降低,队列1的优先级最高。

每个队列执行时间片的长度也不同,规定优先级越低则时间片越长,如逐级加倍。

  新进程进入内存后,先投入队列1的末尾,按FCFS算法调度;

若按队列1一个时间片未能执行完,则降低投入到队列2的末尾,同样按FCFS算法调度;

如此下去,降低到最后的队列,则按“时间片轮转”算法调度直到完成。

  仅当较高优先级的队列为空,才调度较低优先级的队列中的进程执行。

如果进程执行时有新进程进入较高优先级的队列,则抢先执行新进程,并把被抢先的进程投入原队列的末尾。

源代码

#include"

stdio.h"

conio.h"

stdlib.h"

malloc.h"

time.h"

windows.h"

#definenull0

#defineN4

intMN=18;

structcpu{//就绪队列

inttime;

//时间片数量

structpss*head;

structpss*tail;

};

structpss{//进程

charname[5];

intpro_time;

//执行时间

intl_time;

//剩余时间

structpss*next;

voidgotoxy(intx,inty)

{

COORDc;

c.X=x-1;

c.Y=y-1;

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);

}

voidinitial(structcpucpu_quene[])//初始化就绪队列,时间片分别为24816

{

inti,t=2;

for(i=0;

i<

4;

i++)

{cpu_quene[i].time=t;

cpu_quene[i].head=null;

cpu_quene[i].tail=null;

t=2*t;

}

return;

voidcreatpcb(structcpucpu_quene[])//创建进程

structpss*p,*q;

p=(structpss*)malloc(sizeof(structpss));

gotoxy(25,6);

printf("

请输入进程名称:

"

);

scanf("

%s"

p->

name);

gotoxy(25,8);

请输入处理进程需要的时间:

%d"

&

p->

pro_time);

p->

l_time=p->

pro_time;

//剩余时间初始化,初始值为需要时间的值

next=null;

if(cpu_quene[0].head==null)

{cpu_quene[0].head=p;

cpu_quene[0].tail=p;

}

else

{q=cpu_quene[0].tail;

q->

next=p;

voidosdelay(intn)

{inta,i,m;

m=500*n;

a=clock();

;

i++){

if(clock()-a==m)

break;

voidprint(structcpucpu_quene[])

{structpss*p;

gotoxy(23,5);

p=cpu_quene[0].head;

"

while(p!

=null)

{printf("

[%s%d]"

name,p->

l_time);

p=p->

next;

gotoxy(23,7);

p=cpu_quene[1].head;

gotoxy(23,9);

p=cpu_quene[2].head;

gotoxy(23,11);

p=cpu_quene[3].head;

voidnprint(structpss*p)

{gotoxy(27,15);

voidprocess(structcpucpu_quene[N])//进程执行函数

structpss*p,*q,*p1;

inti=0,j,a,b;

intflag1=1;

while(i<

4&

&

cpu_quene[i].head==null){

i++;

}

if(i==4)

printf("

\n无需要处理的进程!

else

{if(i==3)

a=1;

a=2;

for(;

flag1==1;

{switch(a)

{case1:

{if(cpu_quene[i].head!

{p=cpu_quene[i].head;

gotoxy(27,15);

nprint(p);

while(p!

{

while(p->

l_time!

=0)

{osdelay

(1);

p->

l_time-1;

//剩余时间-1?

进程%s处理完毕,离开队列!

cpu_quene[i].head=p->

print(cpu_quene);

gotoxy(MN,18);

[%s%d]"

//输出执行结果

MN=MN+9;

free(p);

//释放内存

p=cpu_quene[i].head;

gotoxy(10,2);

所有进程处理完毕!

{gotoxy(10,2);

flag1=0;

}

case2:

{p=cpu_quene[i].head;

for(;

cpu_quene[i].head!

=null;

{cpu_quene[i].head=p->

gotoxy(27,15);

b=cpu_quene[i].time;

while(p->

=0&

b!

p->

b--;

//时间片减1

if(p->

l_time==0)//剩余时间为零

{gotoxy(27,15);

//输出完成进程

else{

j=i+1;

if(cpu_quene[j].head!

=null)//p=cpu_quene[i].head

{q=cpu_quene[j].tail;

cpu_quene[j].tail=p;

q->

else

{cpu_quene[j].head=p;

p->

print(cpu_quene);

p=cpu_quene[i].head;

if(i==3)

break;

}

voidmain()

{inti,j,flag=1,t=2;

chara;

structpss*p1;

structcpucpu_quene[4];

initial(cpu_quene);

//创建就绪队列

flag==1;

){

gotoxy(20,4);

┏━━━━━━━━━━━━━━━━━━┓"

for(j=5;

j<

10;

j++)

{gotoxy(20,j);

┃┃"

gotoxy(20,10);

┗━━━━━━━━━━━━━━━━━━┛"

creatpcb(cpu_quene);

//创建进程

gotoxy(25,12);

继续输入进程?

(Y/N)"

a);

if(a=='

n'

||a=='

N'

{flag=0;

system("

cls"

//消除上一次回车的内容

待处理进程:

p1=cpu_quene[0].head;

while(p1!

=null){

p1->

name,p1->

p1=p1->

next

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

当前位置:首页 > 人文社科 > 法律资料

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

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