计算机操作系统实验报告Word文件下载.docx
- 文档编号:15185704
- 上传时间:2022-10-28
- 格式:DOCX
- 页数:21
- 大小:206.18KB
计算机操作系统实验报告Word文件下载.docx
《计算机操作系统实验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《计算机操作系统实验报告Word文件下载.docx(21页珍藏版)》请在冰豆网上搜索。
其中预计运行时间和资源需求随机生成(1—20个时间片,A资源0-5,B资源0-3,C资源0-4)。
2.系统开始从后备队列中调入10个作业进入系统。
以后每完成一个作业就从后备队列中调入一个,直到所有作业完成。
3.系统为每个作业创建一个进程,按JCB分配系统资源。
共有3类系统资源,其中A类资源50个,B类资源30个,C类资源40个)。
4.进程在运行过程中(即每个时间片内),可能会申请新的资源(申请的各类资源个数均不超过2)。
用银行家算法控制资源的分配,避免死锁。
注意,每个进程申请各类资源的数目不能超过系统资源总数的二分之一。
5.创建三个阻塞队列A、B、C,分别记录因资源请求而阻塞的进程。
6.可视化编程,形象地展现进程运行的状态。
四、代码实现:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceprocess_scheduling
{
publicpartialclassForm1:
Form
{
StringBuildersb=newStringBuilder();
staticinttimeflat=0;
staticint[,]max=newint[100,3];
staticint[,]allocation=newint[100,3];
staticint[,]need=newint[100,3];
publicstructJCB
publicintflag;
publicStringname;
//作业名
publicintservertime;
//服务时间
publicintarrivetime;
//到达时间
publicintremaintime;
//剩余服务时间
publicintf;
//阻塞时获得资源变成就绪状态标志
};
Queue<
JCB>
pqueue=newQueue<
();
//后备队列
rqueue=newQueue<
//就绪队列
blockA=newQueue<
//阻塞A队列
blockB=newQueue<
//阻塞B队列
blockC=newQueue<
//阻塞C队列
int[]resource=newint[3]{50,30,40};
//分别是资源A,B,C和它们的数量
staticJCB[]job=newJCB[100];
publicForm1()
InitializeComponent();
}
privatevoidForm1_Load(objectsender,EventArgse)
sb.Append("
"
);
Randomrd=newRandom();
for(inti=0;
i<
100;
i++)
job[i].flag=i;
job[i].name="
作业"
+i;
job[i].servertime=rd.Next(1,20);
max[i,0]=rd.Next(0,5);
max[i,1]=rd.Next(0,3);
max[i,2]=rd.Next(0,4);
job[i].arrivetime=i;
job[i].remaintime=job[i].servertime;
privatevoidbt_run_Click(objectsender,EventArgse)
if(tb_timeflat.Text.Length>
0)
timeflat=Convert.ToInt32(tb_timeflat.Text);
else
if(tb_timeflat.Text.Length==0)
请输入时间片!
sb.Append(Environment.NewLine);
tb_content.Text=sb.ToString();
if(timeflat<
=0||timeflat>
20)
时间片大小不合法!
run();
publicvoidrun()
intcount=0;
pqueue.Enqueue(job[i]);
while(pqueue.Count!
=0||rqueue.Count!
=0)
{
addprocess(refcount,10);
//showqueue(rqueue);
if(rqueue.Count==0||rqueue.Peek().arrivetime>
count)
if(blockA.Count==0&
&
blockB.Count==0&
blockC.Count==0)
sb.Append(count.ToString());
处理机处理空转"
count++;
wakeup();
JCBpro1=newJCB();
pro1=rqueue.Dequeue();
if(allocation[pro1.flag,0]==max[pro1.flag,0])
if(allocation[pro1.flag,1]==max[pro1.flag,1])
if(allocation[pro1.flag,2]==max[pro1.flag,2])
if(pro1.remaintime>
=timeflat&
pro1.servertime>
=timeflat)
pro1.remaintime-=timeflat;
时间:
作业名:
服务总时间:
剩余服务时间状态"
sb.Append(count);
--"
sb.Append((count+timeflat));
"
sb.Append(pro1.name);
sb.Append(pro1.servertime);
sb.Append(pro1.remaintime);
if(pro1.remaintime==0)
进程结束"
else
运行中"
sb.Append(Environment.NewLine);
count+=timeflat;
//当前时间加上时间片
if(pro1.remaintime!
addprocess(refcount,9);
//加回之前确保在这之前的进程加入到就绪队列里,9确保能有位置加入
rqueue.Enqueue(pro1);
//加回就绪队列
showqueue(rqueue);
sb.Append((count+pro1.remaintime));
sb.Append(pro1.name);
sb.Append(pro1.servertime);
0进程结束"
count+=pro1.remaintime;
pro1.remaintime=0;
//进程结束查看阻塞队列
if(pro1.remaintime==0)
relaxresource(pro1);
阻塞"
blockC.Enqueue(pro1);
blockB.Enqueue(pro1);
blockA.Enqueue(pro1);
//银行家算法
privateintallocationarithmetic(inti,intrequestA,intrequestB,intrequestC)
intrtn=1;
//资源A
if(requestA<
=resource[0]&
requestA<
=need[i,0])
if(requestA>
resource[0]-=requestA;
//减去相应资源
need[i,0]-=requestA;
//减去相应需求资源数
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 操作系统 实验 报告