进程调度实验报告Word文档格式.doc
- 文档编号:3630122
- 上传时间:2023-05-02
- 格式:DOC
- 页数:12
- 大小:151.27KB
进程调度实验报告Word文档格式.doc
《进程调度实验报告Word文档格式.doc》由会员分享,可在线阅读,更多相关《进程调度实验报告Word文档格式.doc(12页珍藏版)》请在冰点文库上搜索。
进程所需时间片数=0?
撤销该进程
就绪队列为空吗?
占用CPU的时间片数=轮转时间片数?
占用CPU的时间片数置为0
把该进程插入就绪队列尾
四、实验要求
1.产生的各种随机数的取值范围加以限制,如所需的CPU时间限制在1~20之间。
2.进程数n不要太大通常取4~8个
3.使用动态数据结构
4.独立编程
5.至少三种调度算法
6.若有可能请在图形方式下,将PCB的调度用图形成动画显示。
五实验源程序
主函数控制台Main.c
#include<
stdio.h>
windows.h>
#include"
fcfs.h"
privilege.h"
round.h"
voidmain()
{
intn;
cout<
<
"
输入随机产生的进程数目"
endl;
cin>
>
n;
intchoice=1;
while(choice!
=5)
{
cout<
请输入你的选择"
1:
FCFS调度算法\n"
2:
动态优先权调度算法\n"
3:
时间片轮转法\n"
4:
清屏\n"
5:
退出"
cin>
choice;
switch(choice)
{
case1:
{structprocess*first=creatlist(n);
print(first);
fcfs(first);
break;
}
case2:
{structprocess1*first1=creatlist1(n);
print1(first1);
privilege(first1);
case3:
{structprocess2*first=creatlist2(n);
print2(first);
round(first);
case4:
{system("
cls"
);
case5:
break;
default:
}
}
//*/
先来先服务调度算法:
fcfs.h
#ifndefFCFS_H
#defineFCFS_H
stdlib.h>
time.h>
iostream.h>
iomanip.h>
#definerandom(x)(rand()%x)
structprocess
intnum;
//进程号
intattime,servtime;
//进程到达时间,服务时间
process*next;
};
structprocess*creatlist(int);
//新建一个链表
voidinsert(structprocess*first,structprocess*s);
//插入一个节点(尾插法)
voidprint(structprocess*first);
//打印函数
structprocess*creatlist(intn)
srand((int)time(0));
structprocess*first=newprocess;
first->
next=NULL;
for(inti=0;
i<
i++)
structprocess*s;
s=newprocess;
s->
num=i;
attime=i;
servtime=random(20);
insert(first,s);
returnfirst;
voidinsert(structprocess*first,structprocess*s)
structprocess*r=first;
structprocess*p;
while(r){p=r;
r=r->
next;
p->
next=s;
p=s;
voidprint(structprocess*first)//打印函数
p=first->
随机产生的进程的信息如下"
进程名"
进程到达时间"
进程服务时间"
while(p)
p->
num<
'
\t'
attime<
setw(14)<
servtime<
p=p->
voidfcfs(structprocess*first)
intstartime=0;
//开始执行时间
intfinishtime=0;
//完成时间
intwasttime=0;
//周转时间
intweighttime=0;
//带权周转时间
structprocess*p=first->
structprocess*r;
/**************************************************/"
FCFS调度算法基本信息\n"
进程名"
到达时间"
服务时间"
开始执行时间"
完成时间"
周转时间"
带权周转时间"
finishtime=p->
servtime+startime;
wasttime=finishtime-p->
attime;
weighttime=wasttime/p->
servtime;
setw(8)<
setw(10)<
startime<
finishtime<
wasttime<
weighttime<
r=p;
startime+=r->
#endif
动态优先权调度算法privilege.h
#ifndefPRIVILEGE_H
#definePRIVILEGE_H
structprocess1
intpcb;
//进程号PCB
intprivilege,cpu;
//进程优先权,所需CPU时间
process1*next;
/*******************优先权调度算法所需函数声明*****************************************************/
structprocess1*creatlist1();
//新建链表(就绪队列)
voidinsert1(structprocess1*first,structprocess1*s);
//增加一个进程或将一个进程查入到队列中
voiddel1(structprocess1*first,structprocess1*s);
//删除(撤销)一个进程
voidprint1(structprocess1*first);
//打印函数
structprocess1*search(structprocess1*head,structprocess1*s);
/*******************优先权调度算法所需函数*****************************************************/
structprocess1*creatlist1(intn)
structprocess1*first=newprocess1;
first->
structprocess1*s;
s=newprocess1;
pcb=i;
privilege=random(20)+5;
cpu=random(20)+1;
insert1(first,s);
voidinsert1(structprocess1*first,structprocess1*s)//插入节点
structprocess1*p=search(first,s);
s->
next=p->
//return;
structprocess1*search(structprocess1*first,structprocess1*s)//查找第一个到达时间大于等于AT的节点,返回其前一个指针
structprocess1*p,*q;
p=first;
q=first->
while(q!
=NULL&
&
q->
privilege>
=s->
privilege)
p=q;
q=q->
returnp;
voiddel1(structprocess1*first,structprocess1*s)
structprocess1*p,*r;
p=first->
r=first;
inta=1;
while(a)
if(p==s)
r->
//free(p);
a=0;
else
r=p;
p=p->
voidprint1(structprocess1*first)//打印函数
structprocess1*p;
进程号"
进程优先权"
进程所需CPU片数"
pcb<
privilege<
setw(12)<
cpu<
voidprivilege(structprocess1*first)
structprocess1*p,*r=first,*t;
intb=0;
while(first->
next)
r=first;
p=first->
/********************"
b<
*****************************/"
***********进程运行前****************"
print1(r);
p->
cpu=p->
cpu-1;
privilege=p->
privilege-3;
if(p->
0)
p->
privilege=0;
***********进程运行后**********************"
/*************************************************/\n"
cpu==0)
del1(r,p);
else
t=p;
insert1(r,p);
b++;
时间片轮转调度算法round.h
#ifndefROUND_H
#defineROUND_H
structprocess2
//进程号PCB
introundpiece;
//轮转时间片数
intneedpiece;
//进程所需时间片数
intcpupiece;
//占用CPU时间片数
process2*next;
structprocess2*creatlist2(int);
voidprint2(structprocess2*first);
voidinsert2(structprocess2*first,structprocess2*s);
//插入节点
voiddel2(structprocess2*first,structprocess2*s);
//删除一个进程
structprocess2*creatlist2(intn)
structprocess2*first=newprocess2;
structprocess2*s;
s=newprocess2;
pcb=i;
roundpiece=random
(2)+1;
needpiece=random(20);
cpupiece=0;
insert2(first,s);
voidinsert2(structprocess2*first,structprocess2*s)
structprocess2*r=first;
structprocess2*p;
voiddel2(structprocess2*first,structprocess2*s)
structprocess2*p,*r;
voidprint2(structprocess2*first)//打印函数
//cout<
轮转时间片数"
所需时间片数"
占用时间片数"
roundpiece<
needpiece<
cpupiece<
setw(5)<
voidround(structprocess2*first)
structprocess2*p,*r=first;
//r=first;
-------------进程运行前-------------"
print2(r);
needpiece=p->
needpiece-1;
cpupiece=p->
cpupiece+1;
-------------进程运行后-------------"
needpiece<
=0)
del2(r,p);
if(p->
cpupiece==p->
roundpiece)
{
p->
del2(r,p);
insert2(r,p);
}
六实验结果
输入随机产生的进程数目4
输入选择调度算法1
输入选择调度算法2
输入选择调度算法3
七实验总结
通过次实验模拟在单处理机情况下的处理机调度问题,加深了对进程调度的理解。
在次试验中,由于各个调度算法用到的数据结构不同,所以采用了不同的结构体来存放各个调度算法所用的信息。
在动态优先权调度算法中,当前进程用完时间片后,其优先权减去一个常数3,有可能出现优先权低于0的情况,在此情况下没有采取其它措施,后来经老师提醒改为低于0时,就将其优先权置为0,这样就好了。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 进程 调度 实验 报告