操作系统实验报告.docx

上传人:b****3 文档编号:486768 上传时间:2022-10-10 格式:DOCX 页数:98 大小:833.16KB
下载 相关 举报
操作系统实验报告.docx_第1页
第1页 / 共98页
操作系统实验报告.docx_第2页
第2页 / 共98页
操作系统实验报告.docx_第3页
第3页 / 共98页
操作系统实验报告.docx_第4页
第4页 / 共98页
操作系统实验报告.docx_第5页
第5页 / 共98页
点击查看更多>>
下载资源
资源描述

操作系统实验报告.docx

《操作系统实验报告.docx》由会员分享,可在线阅读,更多相关《操作系统实验报告.docx(98页珍藏版)》请在冰豆网上搜索。

操作系统实验报告.docx

操作系统实验报告

 

徐州工程学院

管理学院实验报告

 

实验课程名称:

计算机操作系统

实验地点:

南主楼七楼机房

2014年2月至2014年4月

 

专业信息管理与信息系统

班级11信管2班

学生姓名xxx

学号 

指导老师刘一男

实验报告

实验项目:

分时系统

实验学时:

2

实验日期:

2013-2-28

实验要求:

加深学生对多道系统中进程管理的理解,了解进程的各种状态及其转换过程,分时系统中时间片的设置及进程在时间片开始和结束时的调度过程。

实验内容:

(1)利用程序设计语言模拟分时系统中多个进程按时间片轮转调度算法进行进程调度的过程;

(2)假设有五个进程A,B,C,D,E,它们的到达时间及要求服务的时间分别为:

进程名

A

B

C

D

E

到达时间

0

1

2

3

4

服务时间

4

3

4

2

4

时间片大小为1,利用程序模拟A,B,C,D,E五个进程按时间片轮转的调度及执行过程并计算各进程的周转时间及带权周转时间。

(3)修改时间片大小为2,利用程序模拟A,B,C,D,E五个进程按时间片轮转的调度及执行过程并计算各进程的周转时间及带权周转时间。

(4)修改时间片大小为4,利用程序模拟A,B,C,D,E五个进程按时间片轮转的调度及执行过程并计算各进程的周转时间及带权周转时间。

时间片的大小对计算机的性能产生什么影响?

在时间片轮转算法中,时间片的大小对系统性能有很大的影响,如选择很小的时间片将有利于段作业,因为它能较快地完成,但会频繁地发生中断、进程上下文的切换,从而增加系统的开销,降低了CPU效率;反之,如选择太长的时间片,使得每个进程都能在一个时间片内完成,时间片轮转算法便退化为FCFS算法,无法满足交互式用户的需求。

一个较为可取的大小是,时间片略大于一次典型的交互所需要的时间。

这样可使大多数进程在一个时间片内完成。

源代码:

#include"stdio.h"

#include"stdlib.h"

#include"iostream.h"

#include"cstdlib"

structprocess

{

charname;

intarri_time;//arrivedtime

intserv_time;//serveredtime

inthave_done_time;//已经运行时间

intdone_time;//完成时间

intturn_around_time;//周转时间

floatwei_turn_around_time;//带权周转时间

structprocess*next;

};

inttime=-1;

inttime_slice=4

;//时间片初始值为1

Isempty(structprocess*head)

{

if(head->next==NULL)

returntrue;

elsereturnfalse;

}

voidpushline(structprocess*head,structprocess*rn)

{

if(rn==NULL)

return;

structprocess*x;

x=head;

while(x->next!

=NULL)

{

x=x->next;

}

x->next=rn;

}

voidpopline(structprocess*head,structprocess**x)

{

if(!

Isempty(head))

{

*x=head->next;

head->next=(*x)->next;

(*x)->next=NULL;

}

}

voidisnewcome(structprocess*head,structprocess*readyline)

{

structprocess*x;

if(head->next==NULL)

return;

if(head->next->arri_time==time&&head->next!

=NULL)

{

cout<

popline(head,&x);

pushline(readyline,x);

}

}

voidmain()

{

structprocess*head;

structprocess*newnode;

structprocess*tail;

structprocess*readyline;//队列

readyline=(structprocess*)malloc(sizeof(process));

readyline->next=NULL;

inti;

structprocess*rightnow;

structprocess*p;

/*structprocess*n;*/

head=(structprocess*)malloc(sizeof(process));

if(!

head)

{

cout<<"内存分配错误"<

}

head->next=NULL;

tail=head;

while

(1)

{

newnode=(structprocess*)malloc(sizeof(process));

cout<<"请输入进程名"<

cin>>newnode->name;

if(newnode->name=='#')

break;

cout<<"请输入进程到达时间"<

cin>>newnode->arri_time;

cout<<"请输入进程服务时间"<

cin>>newnode->serv_time;

newnode->done_time=0;

newnode->turn_around_time=0;

newnode->wei_turn_around_time=0.0;

newnode->have_done_time=0;

//tail->next=newnode;

newnode->next=NULL;

//tail=newnode;

pushline(head,newnode);

}

p=head->next;

while(p!

=NULL)

{

cout<name<<"进程"<

p=p->next;

}

ss:

while(time<200)

{

time++;

//cout<<"当前TIME"<

isnewcome(head,readyline);

if(time!

=0)

pushline(readyline,rightnow);

i=time_slice;

//cout<<"i="<

while(i!

=0)

{

//cout<<"DANGQIANGTIME"<

if(i==time_slice)

{

i--;

if(!

Isempty(readyline))

{

popline(readyline,&rightnow);

rightnow->have_done_time++;

rightnow->done_time=time;

cout<<"run"<name<

if(rightnow->have_done_time==rightnow->serv_time)

{rightnow->turn_around_time=rightnow->done_time-rightnow->arri_time+1;

rightnow->wei_turn_around_time=(float)rightnow->turn_around_time/rightnow->serv_time;

cout<<"********************"<name<<"havedone!

"<

cout<<"turn_around_time:

"<turn_around_time<

cout<<"wei_turn_around_time:

"<wei_turn_around_time<

cout<<"********************"<

rightnow=NULL;

gotoss;

}

//else

//pushline(readyline,rightnow);

}

else//break;

gotoss;

}

else

{

i--;

time++;

isnewcome(head,readyline);

//popline(readyline,&rightnow);

rightnow->have_done_time++;

rightnow->done_time=time;

cout<<"run"<name<

if(rightnow->have_done_time==rightnow->serv_time)

{

rightnow->turn_around_time=rightnow->done_time-rightnow->arri_time+1rightnow->wei_turn_around_time=(float)rightnow->turn_around_time/rightnow->serv_time;

cout<<"********************"<name<<"havedone!

"<

cout<<"turn_around_time:

"<turn_around_time<

"<wei_turn_around_time<

cout<<"********************"<

rightnow=NULL;

gotoss;

}

//else

//pushline(readyline,rightnow);

}

}}

/*readyline=head->next;

head=readyline->next;

p=readyline;

readyline=read

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

当前位置:首页 > 法律文书 > 起诉状

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

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