《操作系统》进程调度实验报告.docx
- 文档编号:5361245
- 上传时间:2022-12-15
- 格式:DOCX
- 页数:14
- 大小:123.75KB
《操作系统》进程调度实验报告.docx
《《操作系统》进程调度实验报告.docx》由会员分享,可在线阅读,更多相关《《操作系统》进程调度实验报告.docx(14页珍藏版)》请在冰豆网上搜索。
《操作系统》进程调度实验报告
___大学___学院实验报告
课程名称:
计算机操作系统实验名称:
进程调度实验实验日期:
班级:
姓名:
学号:
仪器编号:
XX
实验报告要求:
1.实验目的2.实验要求3.实验步骤4.程序清单5.运行情况6.流程图7.实验体会
1、实验目的
用高级语言编写和调试一个进程调度程序,以加深对进程的概念及进程调度算法的理解。
2、实验要求
编写并调试一个模拟的进程调度程序,采用“最高优先数优先”调度算法对五个进程进行调度。
“最高优先数优先”调度算法的基本思想是把CPU分配给就绪队列中优先数最高的进程。
静态优先数是在创建进程时确定的,并在整个进程运行期间不再改变。
动态优先数是指进程的优先数在创建进程时可以给定一个初始值,并且可以按一定原则修改优先数。
例如:
在进程获得一次CPU后就将其优先数减少1,或者,进程等待的时间超过某一时限时增加其优先数的值,等等。
编写并调试一个模拟的进程调度程序,采用“轮转法”调度算法对五个进程进行调度。
轮转法可以是简单轮转法、可变时间片轮转法,或多队列轮转法。
简单轮转法的基本思想是:
所有就绪进程按FCFS排成一个队列,总是把处理机分配给队首的进程,各进程占用CPU的时间片相同。
如果运行进程用完它的时间片后还为完成,就把它送回到就绪队列的末尾,把处理机重新分配给队首的进程,直至所有的进程运行完毕。
3、实验步骤
(1)理解实验要求,联系所学知识;
(2)根据要求编写调度算法;(3)编写完整的实验代码并在VC++6.0环境下编译运行;(4)调试程序直至得出结果。
4、程序清单
#include"stdio.h"
#include
#include
#definegetpch(type)(type*)malloc(sizeof(type))
#defineNULL0
structpcb{
charname[10];
charstate;
intsuper;
intntime;
intrtime;
structpcb*link;
}*ready=NULL,*p;
typedefstructpcbPCB;
voidsort()
{
PCB*first,*second;
intinsert=0;
if((ready==NULL)||((p->super)>(ready->super)))
{
p->link=ready;
ready=p;
}
else
{
first=ready;
second=first->link;
while(second!
=NULL)
{
if((p->super)>(second->super))
{
p->link=second;
first->link=p;
second=NULL;
insert=1;
}
else
{
first=first->link;
second=second->link;
}
}
if(insert==0)first->link=p;
}
}
voidinput()
{
inti;
system("cls");
printf("\n\n\t\t*********************************************\t\t\n");
printf("\t\t\t\t最高优先数优先算法\n");
printf("\t\t*********************************************\t\t\n");
printf("\n请输入五个进程信息:
\n");
for(i=0;i<5;i++)
{
printf("\n进程号No.%d:
\n",i);
p=getpch(PCB);
printf("\n输入进程名:
");
scanf("%s",p->name);
printf("\n输入进程优先数:
");
scanf("%d",&p->super);
printf("\n输入进程运行时间:
");
scanf("%d",&p->ntime);
printf("\n");
p->rtime=0;p->state='w';
p->link=NULL;
sort();
}}
intspace()
{
intl=0;PCB*pr=ready;
while(pr!
=NULL)
{
l++;
pr=pr->link;
}
return(l);
}
voiddisplay(PCB*pr)
{
printf("\npname\tstate\tsuper\tndtime\truntime\n");
printf("|%s\t",pr->name);
printf("|%c\t",pr->state);
printf("|%d\t",pr->super);
printf("|%d\t",pr->ntime);
printf("|%d\t",pr->rtime);
printf("\n");
}
voidcheck()
{
PCB*pr;
printf("\n****当前正在运行的进程是:
%s",p->name);
display(p);
pr=ready;
printf("\n****当前就绪队列状态为:
\n");
while(pr!
=NULL)
{
display(pr);
pr=pr->link;
}
}
voiddestroy()
{
printf("\n进程[%s]已完成.\n",p->name);
free(p);
}
voidrunning()
{
(p->rtime)++;
if(p->rtime==p->ntime)
destroy();
else
{(p->super)--;
p->state='w';
sort();
}
}
voidPriority()
{
intlen,h=0;
charch;
system("cls");
input();
len=space();
while((len!
=0)&&(ready!
=NULL))
{
ch=getchar();
h++;
printf("\nTheexecutenumber:
%d\n",h);
p=ready;
ready=p->link;
p->link=NULL;
p->state='R';
check();
running();
printf("\n按任一键继续......");
}
printf("\n\n进程已经完成.\n");
ch=getchar();
}
voidsort1()
{
PCB*q;
q=ready;
if(ready==NULL)ready=p;
else
{
while(q->link!
=NULL){q=q->link;}
q->link=p;
}
}
voidrunning1()
{
(p->rtime)++;
if(p->rtime==p->ntime)
destroy();
else
{
p->state='w';
sort1();
}
}
voidinput1()
{
inti;
system("cls");
printf("\n\n\t\t*********************************************\t\t\n");
printf("\t\t\t\t轮转法算法\n");
printf("\t\t*********************************************\t\t\n");
printf("\n请输入五个进程信息:
\n");
for(i=0;i<5;i++)
{
printf("\n进程号No.%d:
\n",i);
p=getpch(PCB);
printf("\n输入进程名:
");
scanf("%s",p->name);
printf("\n输入进程运行时间:
");
scanf("%d",&p->ntime);
printf("\n");
p->rtime=0;p->state='w';
p->link=NULL;
sort1();
}
}
voiddisplay1(PCB*pr)
{
printf("\npname\tstate\tndtime\truntime\n");
printf("|%s\t",pr->name);
printf("|%c\t",pr->state);
printf("|%d\t",pr->ntime);
printf("|%d\t",pr->rtime);
printf("\n");
}
voidcheck1()
{
PCB*pr;
printf("\n****当前正在运行的进程是:
%s",p->name);
display1(p);
pr=ready;
printf("\n****当前就绪队列状态为:
\n");
while(pr!
=NULL)
{
display1(pr);
pr=pr->link;
}
}
voidRoundRobin()
{
intlen,h=0;
charch;
system("cls");
input1();
len=space();
while((len!
=0)&&(ready!
=NULL))
{
ch=getchar();
h++;
printf("\nTheexecutenumber:
%d\n",h);
p=ready;
ready=p->link;
p->link=NULL;
p->state='R';
check1();
running1();
printf("\n按任一键继续......");
}
printf("\n\n进程已经完成.\n");
ch=getchar();
}
voidmenu()
{intm;
system("cls");
printf("\n\n\t\t*********************************************\t\t\n");
printf("\t\t\t\t实验一进程调度实验\n");
printf("\t\t*********************************************\t\t\n");
printf("\n\n\n\t\t\t1.最高优先数优先算法.");
printf("\n\t\t\t2.轮转法算法.");
printf("\n\t\t\t0.退出程序.");
printf("\n\n\t\t\t\t请按键选择进程调度方法:
");
scanf("%d",&m);
switch(m)
{case1:
Priority();
system("cls");
menu();
break;
case2:
RoundRobin();
system("cls");
menu();
break;
case0:
system("cls");
break;
default:
system("cls");
menu();
}}
voidmain()
{
menu();
}
5、运行情况
按提示操作,直至程序运行完毕,即可得结果。
6、流程图
7、心得体会
通过这次实验,让我把课本中的理论知识转化为实践,在一定程度上加深了我对优先级数调度和轮转法调度算法的理解,同时也提高了我的动手编程能力。
虽然在编程的过程中,遇到了不少的困难,但通过复习课本上的知识点以及到网上搜索相关知识等途径,我顺利地运行实现了本次程序。
另外,好长一段时间没有接触VC++6.0,这次实验又让我重新熟悉编程环境,受益颇多。
教师评价
优秀
良好
中等
及格
不及格
教师签名
日期
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 进程 调度 实验 报告