实验四--磁盘调度

上传人:我*** 文档编号:136390879 上传时间:2020-06-28 格式:DOC 页数:9 大小:37KB
返回 下载 相关 举报
实验四--磁盘调度_第1页
第1页 / 共9页
实验四--磁盘调度_第2页
第2页 / 共9页
实验四--磁盘调度_第3页
第3页 / 共9页
实验四--磁盘调度_第4页
第4页 / 共9页
实验四--磁盘调度_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《实验四--磁盘调度》由会员分享,可在线阅读,更多相关《实验四--磁盘调度(9页珍藏版)》请在金锄头文库上搜索。

1、实验四 磁盘调度一、实验目的:磁盘是高速、大容量、旋转型、可直接存取的存储设备。它作为计算机系统的辅助存储器,担负着繁重的输入输出工作,在现代计算机系统中往往同时会有若干个要求访问磁盘的输入输出要求。系统可采用一种策略,尽可能按最佳次序执行访问磁盘的请求。由于磁盘访问时间主要受寻道时间T的影响,为此需要采用合适的寻道算法,以降低寻道时间。本实验要求学生模拟设计一个磁盘调度程序,观察调度程序的动态运行过程。通过实验让学生理解和掌握磁盘调度的职能。二、实验内容:模拟电梯调度算法,对磁盘进行移臂操作三、提示及要求:1假设磁盘只有一个盘面,并且磁盘是可移动头磁盘。2磁盘是可供多个进程共享的存储设备,但

2、一个磁盘每个时刻只能为一个进程服务。当有进程在访问某个磁盘时,其它想访问该磁盘的进程必须等待,直到磁盘一次工作结束。当有多个进程提出输入输出请求而处于等待状态时,可用电梯调度算法从若干个等待访问者中选择一个进程,让它访问磁盘。为此设置“驱动调度”进程。3由于磁盘与处理器是并行工作的,所以当磁盘在为一个进程服务时,占有处理器的其它进程可以提出使用磁盘(这里我们只要求访问磁道),即动态申请访问磁道,为此设置“接受请求”进程。4为了模拟以上两个进程的执行,可以考虑使用随机数来确定二者的允许顺序,程序结构图参考附图:5“接受请求”进程建立一张“进程请求I/O”表,指出等待访问磁盘的进程要求访问的磁道,

3、表的格式如下:进程名要求访问的磁道号6“磁盘调度”的功能是查“请求I/O”表,当有等待访问的进程时,按电梯调度算法(SCAN算法)从中选择一个等待访问的进程,按其指定的要求访问磁道。SCAN算法参考课本第九章。算法模拟框图略。7附图中的“初始化”工作包括:初始化“请求I/O”表,设置置当前移臂方向;当前磁道号。并且假设程序运行前“请求I/O”表中已有若干进程(48个)申请访问相应磁道。四、附图 五、源程序代码1操作类package SCAN;import java.util.Random;public class SCAN_Operation private String requestPCB

4、 = new String102;/请求进程private String result = new String102;private Random random = new Random();/随机数private int processNum;/请求进程个数/生成随机请求的进程public void RandomRequest() this.processNum = this.random.nextInt(5)+4;for (int i = 0; i this.processNum; i+) this.requestPCBi0 = P+i;this.requestPCBi1 = this.

5、random.nextInt(300) + ;for (int i = 0; i this.processNum; i+) for (int j = 0; j 2; j+) this.resultij = ;/对进程进行排序public void sortProcess() String temp = new String();for (int i = 0; i this.processNum; i+) for (int j = 0; j Integer.parseInt(this.requestPCBj+11) temp = this.requestPCBj0;this.requestPCB

6、j0 = this.requestPCBj+10;this.requestPCBj+10 = temp;temp = this.requestPCBj1;this.requestPCBj1 = this.requestPCBj+11;this.requestPCBj+11 = temp;/执行 方向:1为递增,2为递减public void stepRun(int place,int direction)this.sortProcess();int find = -1;if (direction = 1) for (int i = 0; i place) find = i;break;else

7、 if ( i = this.processNum - 1) find = i;break;int j = 0;for (int i = find; i = 0; i-) this.resultj0 = this.requestPCBi0;this.resultj1 = this.requestPCBi1;j+;if (direction = 2) for (int i = 0; i place) find = i;break;else if ( i = this.processNum - 1) find = i;break;int j = 0;for (int i = find-1; i =

8、 0; i-) this.resultj0 = this.requestPCBi0;this.resultj1 = this.requestPCBi1;j+;for (int i = find; i processNum; i+) this.resultj0 = this.requestPCBi0;this.resultj1 = this.requestPCBi1;j+;public String getRequestPCB() return requestPCB;public void setRequestPCB(String requestPCB) this.requestPCB = re

9、questPCB;public int getProcessNum() return processNum;public void setProcessNum(int processNum) this.processNum = processNum;public String getResult() return result;public void setResult(String result) this.result = result;2界面类package SCAN;import org.eclipse.swt.widgets.Display;import org.eclipse.sw

10、t.widgets.Shell;import org.eclipse.swt.widgets.Label;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.MessageBox;import org.eclipse.swt.widgets.Table;import org.eclipse.swt.widgets.TableColumn;import org.eclipse.swt.widgets.Button;import org.eclipse.swt.widgets.TableItem;import org.eclipse.

11、swt.widgets.Text;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;public class SCANSWT protected Shell shell;private Table table;private Text text;private Table table_1;private MessageBox messageBox;private SCAN_Operation mOperation;/* * Launch the applicat

12、ion. * param args */public static void main(String args) try SCANSWT window = new SCANSWT();window.open(); catch (Exception e) e.printStackTrace();/* * Open the window. */public void open() Display display = Display.getDefault();createContents();shell.open();shell.layout();while (!shell.isDisposed() if (!display.readAndDispatch() display.sleep();/* * Create contents of th

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 事务文书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号