进程调度vc代码计算机操作系统实验.docx

上传人:b****8 文档编号:10628765 上传时间:2023-02-22 格式:DOCX 页数:16 大小:198.76KB
下载 相关 举报
进程调度vc代码计算机操作系统实验.docx_第1页
第1页 / 共16页
进程调度vc代码计算机操作系统实验.docx_第2页
第2页 / 共16页
进程调度vc代码计算机操作系统实验.docx_第3页
第3页 / 共16页
进程调度vc代码计算机操作系统实验.docx_第4页
第4页 / 共16页
进程调度vc代码计算机操作系统实验.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

进程调度vc代码计算机操作系统实验.docx

《进程调度vc代码计算机操作系统实验.docx》由会员分享,可在线阅读,更多相关《进程调度vc代码计算机操作系统实验.docx(16页珍藏版)》请在冰豆网上搜索。

进程调度vc代码计算机操作系统实验.docx

进程调度vc代码计算机操作系统实验

实验报告1

课程计算机操作系统实验名称进程调度第1页

班级11计本学号105032018130姓名风律澈

实验日期:

2018年10月4日报告退发(订正、重做>

一、实验目的:

多道系统中,当就绪进程数大于处理机数时,必须按照某种策略决定选取哪些进程占用处理器。

本实验模拟实现处理器调度,进一步加深对处理器调度算法的理解。

二、实验内容:

选择某种调度算法,设计一个实现处理器调度的程序。

三、实验环境:

VS2008,window7操作系统

四、实验步骤:

1、设计一个有N个进程并发的处理器调度程序,每个进程由一个PCB表示,PCB包含以下信息:

进程名、优先数、要求服务时间、进程状态。

2、可分别用链表表示就绪队列,用队列中的结构体结点表示进程。

3、已知各进程的的到达时间等如下:

进程名

到达时间

服务时间

优先数

A

0

3

12

B

1

5

31

C

2

2

21

D

3

4

10

4、分别实现下面两种调度算法

按FCFS调度算法实现处理器调度;

按优先数调度算法实现处理器调度。

5、?

?

?

?

:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~?

?

?

?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

?

?

?

?

?

?

?

:

link.h

#include

usingnamespacestd?

////

//?

?

?

?

//

////

//?

?

?

?

typedefstructlistnode{

listnode*prior?

charname?

//?

?

?

intserve_time?

//?

?

?

?

intpriors?

//?

?

?

intarrival_time?

//?

?

?

?

floatstart_time?

//?

?

?

?

floatfinish_time?

//?

?

?

?

floatturnover_time?

//?

?

?

?

floatt_t_s?

//?

?

?

?

?

?

?

intstate?

listnode*next?

}progress?

//?

?

?

?

typedefstruct{

listnode*head?

intlength?

}listlead,list?

//?

?

?

?

voidcoutdata(listnode*p>{

cout<<"?

?

?

?

"<name<<""?

cout<<"?

?

?

?

?

"<serve_time<<""?

cout<<"?

?

?

?

"<priors<<""?

cout<<"?

?

?

?

?

"<arrival_time<<""?

cout<<"?

?

?

?

?

"<start_time<<""?

cout<<"?

?

?

?

?

"<finish_time<<""?

cout<<"?

?

?

?

?

"<turnover_time<<""?

cout<<"?

?

?

?

?

?

?

?

"<t_t_s<<""<

}

//?

?

?

?

voidcindata(listnode&e,charn,ints,intp,inttime>{

e.name=n?

e.serve_time=s?

e.priors=p?

e.arrival_time=time?

}

voidcindata(listnode&e>{

cout<<"?

?

?

?

:

"?

cin>>e.name?

cout<<"?

?

?

?

?

:

"?

cin>>e.serve_time?

cout<<"?

?

?

?

:

"?

cin>>e.priors?

}

//?

?

?

voidinitilead(listlead&L>{

L.head=NULL?

L.length=0?

}

voidinitinode(listnode&e,charn,ints,intp,inttime>{

e.prior=NULL?

e.next=NULL?

e.finish_time=0?

e.start_time=0?

e.state=0?

e.turnover_time=0?

e.t_t_s=0?

cindata(e,n,s,p,time>?

}

//?

?

?

?

voidcopy(listnode*p,listnode&e>{

e.arrival_time=p->arrival_time?

e.finish_time=p->finish_time?

e.name=p->name?

e.next=p->next?

e.prior=p->prior?

e.priors=p->priors?

e.serve_time=p->serve_time?

e.start_time=p->start_time?

e.state=p->state?

}

 

////

//?

?

?

?

?

?

//

////

listnode*fin_i(listleadL,inti>{

while(i<1||i>L.length>

{cout<<"i?

?

?

?

?

!

?

?

?

?

?

?

?

?

~"<

cin>>i?

}

listnode*p=L.head?

intj=1?

if(i<=(L.length/2>>{

while(j<=i>{

p=p->next?

j++?

}

returnp?

}

else{

i=L.length-i?

if(i==0>{

returnL.head?

}

else{

while(j<=i>{

p=p->prior?

j++?

}

returnp?

}

}

}

////

//?

?

?

?

?

?

//

////

////

//?

?

//

//?

?

?

?

:

L?

?

?

?

i?

?

?

?

?

?

e?

?

?

?

?

?

?

?

?

?

?

//

////

voidfin_elem(listleadL,inti,listnode&e>{

listnode*p?

p=fin_i(L,i>?

copy(p,e>?

}

////

//*?

?

*//

//?

?

?

?

:

L?

?

?

?

i?

?

?

?

?

?

i?

L.Length+1,e?

?

?

?

?

?

e?

?

?

new?

?

?

?

?

//

////

voidinsert(listlead&L,inti,listnode&e>{

while(i<1||i>L.length+1>

{cout<<"i?

?

?

?

?

!

?

?

?

?

?

?

?

?

~"<

cin>>i?

}

if(i==1>{//?

?

?

?

if(L.length==0>

{L.head=&e?

e.next=&e?

L.length++?

}//?

?

?

?

?

?

elseif(L.length==1>{//?

?

?

?

?

?

L.head->next=&e?

e.next=L.head?

L.head->prior=&e?

L.length++?

}

else{//?

?

?

?

?

?

?

listnode*p=L.head->next?

p->prior=&e?

e.next=p?

L.head->next=&e?

L.length++?

}

}

elseif(i>1&&i{

listnode*p,*q?

//?

?

?

?

p=fin_i(L,i>->prior?

q=p->next?

p->next=&e?

e.next=q?

q->prior=&e?

e.prior=p?

L.length++?

}

else{//?

?

?

?

listnode*p=L.head?

e.next=p->next?

e.prior=p?

p->next=&e?

L.head=&e?

L.length++?

}

}

////

//*?

?

?

?

*//

//?

?

?

?

:

L?

?

?

?

e?

?

?

?

?

?

e?

?

?

new?

?

?

?

?

//

//?

?

?

?

?

?

?

"?

?

?

?

",?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

//

voidprior_insert(listlead&L,listnode&e>{

if(L.length==0>

insert(L,1,e>?

else{

intin=1?

inti=1?

listnode*p=newlistnode(>?

initinode(*p,'x',0,0,0>?

//?

?

?

?

?

?

?

//

do{

fin_elem(L,in,*p>?

if(e.priors>p->priors>//?

?

?

?

?

?

?

//

break?

else

in++?

}while(in<=L.length>?

insert(L,in,e>?

}

}

//?

?

//

//?

?

?

?

:

L?

?

?

?

i?

?

?

?

?

?

//

////

voiddel_elem(listlead&L,inti>{

while(i<1||i>L.length>

{cout<<"i?

?

?

?

?

!

?

?

?

?

?

?

?

?

~"<

cin>>i?

}

listnode*p,*q?

if(i==1>{//?

?

?

?

if(L.length==1>{//?

?

?

?

?

?

deleteL.head?

L.head=NULL?

L.length=0?

}

elseif(L.length==2>{//?

?

?

?

?

?

listnode*p=L.head?

listnode*q?

q=p->next?

p->next=p?

p->prior=NULL?

L.length--?

}

else{//?

?

?

?

?

?

listnode*p=L.head?

listnode*q?

q=p->next?

p->next=q->next?

q->next->prior=NULL?

deleteq?

L.length--?

}

}

elseif(i>1&&i{//?

?

?

?

p=fin_i(L,i>->prior?

q=p->next?

p->next=q->next?

q->next->prior=p?

deleteq?

L.length--?

}

else{//?

?

?

?

listnode*p=L.head->prior?

p->next=L.head->next?

deleteL.head?

L.head=p?

L.length--?

}

}

////

//?

?

//

//?

?

?

?

:

L?

?

?

?

i?

?

?

?

?

?

?

?

?

//

////

voidmodify(listlead&L,inti>{

listnode*p?

p=fin_i(L,i>?

cindata(*p>?

}

////

//?

?

//

//?

?

?

?

:

?

?

?

?

?

L?

?

?

?

?

//

////

voiddel_list(listlead&L>{

listnode*p,*q?

p=L.head?

if(L.length==1>{

del_elem(L,1>?

}

else{

q=p->prior?

while(q->prior!

=NULL>{

deletep?

p=q?

q=p->prior?

}

deleteq?

L.head=NULL?

L.length=0?

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~?

?

?

?

?

?

?

?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

?

?

?

?

?

?

?

:

Assistandextension.h

////

//?

?

?

?

?

//

voidthis_insert(list&ready,intType,listnode*x>{

if(Type==1>

insert(ready,ready.length+1,*x>?

elseif(Type==2>

prior_insert(ready,*x>?

}

 

////

//?

?

?

?

?

?

//

//?

?

?

?

:

?

?

?

?

?

?

?

?

?

?

?

?

ABCD?

?

?

?

?

?

?

?

?

?

//

//type=1,?

?

?

?

?

?

?

?

?

?

type=2,?

?

?

?

?

?

?

?

?

?

//

voidaccident(list&ready,inttime,intType>{

if(time==0>{

progress*x=newprogress(>?

initinode(*x,'A',3,12,time>?

this_insert(ready,Type,x>?

}

elseif(time==1>{

progress*x=newprogress(>?

initinode(*x,'B',5,31,time>?

this_insert(ready,Type,x>?

}

elseif(time==2>{

progress*x=newprogress(>?

initinode(*x,'C',2,21,time>?

this_insert(ready,Type,x>?

}

elseif(time==3>{

progress*x=newprogress(>?

initinode(*x,'D',4,10,time>?

this_insert(ready,Type,x>?

}

elseif(time<0>

cout<<"wrong"?

}

////

//?

?

?

?

//

//?

?

?

?

:

?

?

?

?

?

?

?

FCFS?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

progress?

//

//?

?

?

?

ready?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

ready?

?

?

?

?

progress?

//

//?

?

?

?

?

?

?

//

voidhandle(list&ready,inttime>{

if(ready.head->next->state==0>{

ready.head->next->start_time=time?

ready.head->next->state++?

}

elseif(ready.head->next->state>0>{

if(ready.head->next->state==ready.head->next->serve_time>{

ready.head->next->finish_time=time?

ready.head->next->turnover_time=ready.head->next->finish_time-ready.head->next->arrival_time?

ready.head->next->t_t_s=ready.head->next->turnover_time/ready.head->next->serve_time?

coutdata(ready.head->next>?

ready.head->next->next->start_time=time?

ready.head->next->next->state++?

del_elem(ready,1>?

}

else

ready.head->next->state++?

}

else

cout<<"wrong"<

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~main?

?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

?

?

?

?

?

?

?

:

main.cpp

#include"link.h"

#include"Assistandextension.h"

voidmain(>{

//?

?

?

?

//

inttime=0?

listready?

intType=3?

initilead(ready>?

//?

?

?

?

//

cout<<"?

?

?

?

?

?

?

?

1?

?

FCFS,?

?

2?

?

?

?

?

?

?

?

?

?

?

?

"<

cout<<"?

?

?

?

:

"?

cin>>Type?

do

{

accident(ready,time,Type>?

handle(ready,time>?

time++?

}while(ready.head!

=NULL/*time<10*/>?

}

6、?

?

?

?

:

FCFS?

?

?

?

?

?

?

?

?

?

?

?

?

:

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

当前位置:首页 > 小学教育 > 其它课程

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

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