




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
操作系统实验二内实验报告作者:mo唏【实验题目】:时间片轮转RR进程调度算法【实验目的】 通过这次实验,加深对进程概念的理解,进一步掌握进程状态的转变、进程调度的策略及对系统性能的评价方法。【实验内容】问题描述:设计程序模拟进程的时间片轮转RR调度过程。假设有n个进程分别在T1, ,Tn时刻到达系统,它们需要的服务时间分别为S1, ,Sn。分别利用不同的时间片大小q,采用时间片轮转RR进程调度算法进行调度,计算每个进程的完成时间,周转时间和带权周转时间,并且统计n个进程的平均周转时间和平均带权周转时间。程序要求如下:1)进程个数n;每个进程的到达时间T1, ,Tn和服务时间S1, ,Sn;输入时间片大小q。2)要求时间片轮转法RR调度进程运行,计算每个进程的周转时间,带权周转时间,并且计算所有进程的平均周转时间,带权平均周转时间;3)输出:要求模拟整个调度过程,输出每个时刻的进程运行状态,如“时刻3:进程B开始运行”等等;4)输出:要求输出计算出来的每个进程的周转时间,带权周转时间,所有进程的平均周转时间,带权平均周转时间。 源程序 程序结构:Process.javapackage com.RoundRobin;/* * 功能: * 定义进程类 * method: * 进程按到达时间排序 * 进程 RR 时间片轮转法 * author Rain * */class Process private String name; /进程名private int arriveTime;/到达时间private int serviceTime;/服务时间private int finishTime;/完成时间private int roundTime;/周转时间private double weightroundTime;/带权周转时间private double aveweightroundTime;/平均带权周转时间private double averoundTime;/平均带权周转时间private int temp;private boolean isAction;public Process() name = ;arriveTime = 0;serviceTime = 0;finishTime = 0;roundTime = 0;weightroundTime = 0;averoundTime = 0;aveweightroundTime = 0;temp = 0;isAction = false;public void setName(String name) = name;public void setArriveTime(int arriveTime) this.arriveTime = arriveTime;public void setServiceTime(int serviceTime) this.serviceTime = serviceTime;this.temp = serviceTime;public void sort(Process a) /对进程进行排序for (int j = 1; j = 0) if (temp ajj.arriveTime) ajj + 1 = ajj;jj-; elsebreak;ajj + 1 = b;/for/sort/* * * param a * param q * 时间片轮转算法 */public void RR(Process a, int q) Queue aQueue = new Queue();aQueue.enqueue(0);int j;int i = 1;int time = a0.finishTime;int count = 0;for (int m = 0; m = 0) System.out.print(第+time);time = q + time;aaQueue.front().finishTime = time;System.out.println(到 + aaQueue.front().finishTime + 时间刻+进程 + aaQueue.front().name+在运行);if (aaQueue.front().temp 0) System.out.print(第+time);time = aaQueue.front().temp + q + time;aaQueue.front().finishTime = time;System.out.println(到 + aaQueue.front().finishTime + 时间刻 + 进程 + aaQueue.front().name + 在运行);aaQueue.front().temp = 0;for (j = i; j a.length; j+) if (aj.arriveTime = time) aj.isAction = true;aQueue.enqueue(j); i+;else continue;if (aaQueue.front().temp= 0) aaQueue.front().finishTime = time;if(aQueue.isEmpty() != true)aQueue.dequeue();else temp=aQueue.front();aQueue.dequeue();aQueue.enqueue(temp);for(int jj=0; jja.length; jj+)ajj.roundTime = ajj.finishTime - ajj.arriveTime;ajj.weightroundTime = (double)ajj.roundTime / ajj.serviceTime;a0.aveweightroundTime += ajj.weightroundTime;a0.averoundTime += ajj.roundTime;a0.aveweightroundTime = a0.aveweightroundTime / a.length;a0.averoundTime = a0.averoundTime / a.length;/RR/* * 打印结果 * param a * * */public void print(Process a) System.out.println(进程名 + + 到达时间 + + 服务时间 + + 完成时间+ + 周转时间 + + 带权周转时间);/DecimalFormat df = new DecimalFormat(#.00);for (int ii = 0; ii 0)System.arraycopy(oldData, 0, data, head + 1, tail + 1);head = 0;tail = oldData.length - 1;tail = (tail + 1) % data.length;size+;datatail = obj;/ 队列的元素出队public int dequeue() if (size = 0)throw new NoSuchElementException();int ele = datahead;/ 循环队列/head+;head = (head + 1) % data.length;size-;return ele;RR.javapackage com.RoundRobin;import java.io.*;import java.util.Scanner;import com.RoundRobin.Process ;public class RR /* * param args */public static void main(String args) / TODO Auto-generated method stubSystem.out.println(n-模拟操作系统进程调度- 时间片轮转法-);int i = 0;String S1 = new String20;try FileReader aFileReader = new FileReader(data.txt);BufferedReader in = new BufferedReader(aFileReader);String s = null;while (s = in.readLine() != null) S1i = s;i+;aFileReader.close();in.close(); catch (IOException ioe) System.out.println( ioe.getMessage() );int choice=-1;while( true ) System.out.println( 1.开始或继续:);System.out.println( 0.退出。);System.out.print( 请输入选择:);tryBufferedReader in = new BufferedReader(new InputStreamReader(System.in);String inputString = in.readLine();choice = Integer.valueOf(inputString);if(0 = choice)/System.exit(0);break ;if(1 = choice) Process a = new Processi;for (int ii = 0; ii i; ii+) aii = new Process();String temp = S1ii.split( );int j = 0;aii.setName( tempj );aii.setArriveTime( Integer.parseInt( tempj + 1 ) );aii.setServiceTime( Integer.parseInt( tempj + 2 ) );Process test = new Process(); test.sort(a);System.out.print(请输入时间片的大小:);Scanner reader=new Sca
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 大健康产业创新发展模式研究与实践
- 钢平台安全施工方案
- 跨部门协作事务处理指南与文书流程
- 汽车后市场智能化服务解决方案
- 三农村电子商务发展模式研究方案
- 初级母婴护理师考试复习测试卷
- 妇产科护理练习试题及答案(一)
- 法律实务案例解析知识题
- 城市绿化与生态保护方案
- 影视制作与发行季度报告表
- 基于单片机的电子广告牌设计
- 应用PDCA管理工具提高病案归档率
- 果蔬自发气调包装原理与应用演示文稿
- DB43T 2428-2022 水利工程管理与保护范围划定技术规范
- SB/T 11016-2013足部保健按摩服务规范
- GB/T 4062-2013三氧化二锑
- 神经系统的结构与神经调节的基本方式 【知识精讲+高效备课】 高考生物一轮复习 (新教材)
- GB/T 15328-2019普通V带疲劳试验方法无扭矩法
- 马克思主义基本原理(完整版)
- 涉密人员脱密期管理制度
- 企业风险管理-战略与绩效整合(中文版)
评论
0/150
提交评论