移臂调度算法c语言,磁盘移臂调度算法实验
操作系统实验报告
实验题目:实验八:磁盘移臂调度算法实验
软件环境:Linux操作系统
实验目的:加深对于操作系统设备管理技术的了解,体验磁盘移臂调度算法的重要性;掌握几种重要的磁盘移臂调度算法,练习模拟算法的编程技巧,锻炼研究分析试验数据的能力。
实验内容:请在示例实验程序中补充SCAN,C-SCAN,LOOK磁盘移臂调度算法的模拟程序。输入不同的磁盘柱面请求序列,观察和分析其调度效果和性能,并将其与FCFS和SSTF算法进行比较。改进以上示例实验程序,使之能够随机的产生磁盘柱面请求序列,以便能动态的观测各种调度算法的性能。
实验思路:首先明确了SCAN,C-SCAN,LOOK磁盘移臂调度算法的思想,明确需要完成的任务即给出寻道序列,并根据方向转换次数和寻到数分析算法的优劣并比较。其次,结合私立程序给出的SSTF算法和SCAN算法,写出SCAN,C-SCAN,LOOK算法,并添加到示例程序中。编译后执行,多次磁盘请求序列的测试,查看实验结果是否正确。
实验代码://dask.h
#include
#include
#include
#include
#include
using namespace std;
class DiskArm{
public:
DiskArm();
~DiskArm();
void InitSpace(char * MethodName); //初始化寻道记录
void Report(void); // 报告算法执行情况
void Fcfs(void); //先来先服务算法
void Sstf(void); //最短寻道时间优先算法
void Scan(void); //电梯调度算法
void CScan(void); //均匀电梯调度算法
void Look(void); //LOOK 调度算法
private:
int *Request ;
//磁盘请求道号
int *Cylinder;
//工作柱面道号号
int RequestNumber;
//磁盘请求数
int CurrentCylinder;
//当前道号
int SeekDirection;
//磁头方向
int SeekNumber;
//移臂总数
int SeekChang;
//磁头调头数
};
//dask.c
#include "dask.h"
DiskArm::DiskArm(){
int
i;
//输入当前道号
cout
<< "Please input Current cylinder :"
;
cin
>> CurrentCylinder;
//磁头方向,输入 0 表示向小道号移动,1 表示向大道号移动
cout
<< "Please input Current Direction
(0/1) :" ;
cin
>> SeekDirection;
//输入磁盘请求数,请求道号
cout
<< "Please input Request Numbers :"
;
cin
>> RequestNumber;
cout
<< "Please input Request cylinder
string :";
Request =
new int[sizeof(int) * RequestNumber];
Cylinder
= new int[sizeof(int) * RequestNumber];
for (i =
0; i < RequestNumber; i++)
cin
>> Request[i];
}
DiskArm::~DiskArm(){
}
//初始化道号,寻道记录
void DiskArm::InitSpace(char * MethodName)
{
int
i;
cout
<< endl
<< MethodName
<< endl;
SeekNumber = 0;
SeekChang
= 0;
for (i =
0; i < RequestNumber; i++)
Cylinder[i] = Request[i];
}
// 统计报告算法执行情况
void DiskArm::Report(void){
cout
<< endl;
cout
<< "Seek Number: "
<< SeekNumber
<< endl;
cout
<< "Chang Direction: "
<< SeekChang
<< endl
<< endl;
}
//先来先服务算法
void DiskArm::Fcfs(void)
{
int
Current = CurrentCylinder;
int
Direction = SeekDirection;
InitSpace("FCFS");
cout
<< Current;
for(int
i=0; i
if(((Cylinder[i] >= Current)
&& !Direction)||((Cylinder[i]
< Current) &&
Direction)){
//需要调头
SeekChang++; //调头数加 1
Direction = !Direction ; //改变方向标志
//报告当前响应的道号
cout << endl
<< Current
<< " -> "
<< Cylinder[i];
}
else //不需调头,报告当前响应的道号
cout << " -> "
<< Cylinder[i] ;
//累计寻道数,响应过的道号变为当前道号
SeekNumber += abs(Current -Cylinder[i]);
Current = Cylinder[i];
}
//报告磁盘移臂调度的情况
Report();
}
void DiskArm::Sstf(void)
{
int
Shortest;
int
Distance = 999999 ;
int
Direction = SeekDirection;
int
Current = CurrentCylinder;
InitSpace("SSTF");
cout
<< Current;
for(int
i=0; i
//查找当前最近道号
for(int j=0; j
if(Cylinder[j] == -1) continue; //-1 表示已经响应过了
if(Distance > abs(Current-Cylinder[j])){
//到下一道号比当前距离近,下一道号为当前距离
Distance = abs(Current-Cylinder[j]);
Shortest = j;
}
}
if((( Cylinder[Shortest] >= Current)
&& !Direction)||((
Cylinder[Shortest] < CurrentCylinder)
&& Direction)){
//需要调头
SeekChang++; //调头数加 1
Direction = !Direction ; //改变方向标志
//报告当前响应的道号
cout << endl
<< Current
<< " -> "
<< Cylinder[Shortest];
}
else //不需调头,报告当前响应的道号
cout << " -> "
<< Cylinder[Shortest] ;
//累计寻道数,响应过的道号变为当前道号
SeekNumber += abs(Current -Cylinder[Shortest]);
Current = Cylinder[Shortest];
//恢复最近距离,销去响应过的道号
Distance = 999999;
Cylinder[Shortest] = -1;
}
Report();
}
//电梯调度算法
void DiskArm::Scan(void){
int
Current = CurrentCylinder;
int
Direction = SeekDirection;
InitSpace("SCAN");
cout
<< Current;
for(int
i=0; i
int index=-1;
int Distance = 999999;
for(int j=0;j
if(Cylinder[j]==-1)
continue;
else
if((Direction==0&&Cylinder[j]
||(Direction==1&&Cylinder[j]>Current&&(Cylinder[j]-Current)
index=j;
Distance=abs(Current-Cylinder[j]);
}
}
if(Direction==0){
if(index!=-1){
cout<"<
SeekNumber+=Current-Cylinder[index];
Current=Cylinder[index];
Cylinder[index]=-1;
}else{
cout<"<<0<
SeekNumber+=Current;
Direction=!Direction;
//cout<<0;
Current=0;
SeekChang++;
i--;
}
}
else if(Direction==1){
if(index!=-1){
cout<"<
SeekNumber+=Cylinder[index]-Current;
Current=Cylinder[index];
Cylinder[index]=-1;
}else{
cout<"<<199<
SeekNumber+=199-Current;
Direction=!Direction;
//cout<<199;
Current=199;
SeekChang++;
i--;
}
}
}
//报告磁盘移臂调度的情况
Report();
}
//均匀电梯调度算法
void DiskArm::Look(void){
int
Current = CurrentCylinder;
int
Direction = SeekDirection;
InitSpace("Look");
cout
<< Current;
for(int
i=0; i
int index=-1;
int Distance = 999999;
for(int j=0;j
if(Cylinder[j]==-1)
continue;
else
if((Direction==0&&Cylinder[j]
||(Direction==1&&Cylinder[j]>Current&&(Cylinder[j]-Current)
index=j;
Distance=abs(Current-Cylinder[j]);
}
}
if(Direction==0){
if(index!=-1){
cout<"<
SeekNumber+=Current-Cylinder[index];
Current=Cylinder[index];
Cylinder[index]=-1;
}else{
//cout<
Direction=!Direction;
SeekChang++;
i--;
}
}
else if(Direction==1){
if(index!=-1){
cout<"<
SeekNumber+=Cylinder[index]-Current;
Current=Cylinder[index];
Cylinder[index]=-1;
}else{
//cout<
Direction=!Direction;
SeekChang++;
i--;
}
}
}
//报告磁盘移臂调度的情况
Report();
}
//LOOK 调度算法
void DiskArm::CScan(void)
{
int Current = CurrentCylinder;
int
Direction = SeekDirection;
InitSpace("CScan");
cout
<< Current;
for(int
i=0; i
int index=-1;
int Distance = 999999;
for(int j=0;j
if(Cylinder[j]==-1)
continue;
else
if((Direction==0&&Cylinder[j]
||(Direction==1&&Cylinder[j]>Current&&(Cylinder[j]-Current)
index=j;
Distance=abs(Current-Cylinder[j]);
}
}
if(Direction==0){
if(index!=-1){
cout<"<
SeekNumber+=Current-Cylinder[index];
Current=Cylinder[index];
Cylinder[index]=-1;
}else{
cout<"<<0<
SeekNumber+=Current;
Current=199;
cout<199";
SeekChang++;
i--;
}
}
else if(Direction==1){
if(index!=-1){
cout<"<
SeekNumber+=Cylinder[index]-Current;
Current=Cylinder[index];
Cylinder[index]=-1;
}else{
cout<"<<199<
SeekNumber+=199-Current;
Current=0;
SeekChang++;
i--;
}
}
}
Report();
}
//程序启动入口
int main(int argc,char *argv[]){
//建立磁盘移臂调度类
DiskArm *dask = new DiskArm();
//比较和分析 FCFS 和 SSTF 两种调度算法的性能
dask->Fcfs();
dask->Sstf();
dask->Scan();
dask->CScan();
dask->Look();
}
移臂调度算法c语言,磁盘移臂调度算法实验相关推荐
- 移臂调度算法java_C语言 磁盘调度模拟
什么是磁盘调度? 磁盘调度指待的是访问的磁道时,当前磁头访问的方式(也指待是算法).磁盘的访问也是一种I/O设备的访问,在数据访问中需要知道如何去访问从内存以及I/O传输过来的数据.怎么样去存储或者是 ...
- 1.2.7存储结构-磁盘管理:磁盘移臂调度算法、先来先服务(FCFS)、最短寻道时间优先(SSTF)、扫描算法(SCAN)、循环扫描(CSCAN)
1.2.7存储结构-磁盘管理:磁盘移臂调度算法.先来先服务(FCFS).最短寻道时间优先(SSTF).扫描算法(SCAN).循环扫描(CSCAN) 先来先服务(FCFS) 最短寻道时间优先(SSTF) ...
- Mac运行已安装软件提示“XXX 已损坏,打不开。移到废纸篓/推出磁盘映像。”解决方法
最近因需要打算在Mac上安装Windows11双系统,需要绕过Windows11的TPM2.0检测,需要把Windows11的win.install的文件替换成Windows10的win.instal ...
- mac“XXX 已损坏,无法打开。移到废纸篓/推出磁盘映像。”
如果mac电脑,已经打开「设置」中的「安全性」信任「任何来源」,依旧提示: "XXX 已损坏,无法打开.移到废纸篓/推出磁盘映像." 解决办法如下:打开「终端」执行如下命令: ~ ...
- 操作系统实验:驱动调度 模拟电梯调度算法 C语言实现
一:实验内容 模拟电梯调度算法,对磁盘进行移臂和旋转调度. 二.实验题目 (1)."驱动调度"进程和"接收请求"进程能否占有处理器运行,取决于磁盘的结束中断信 ...
- 【嵌入式开发】ARM 代码搬移 ( ARM 启动流程 | 代码搬移 起点 终点 | 链接地址 | 汇编代码 )
文章目录 一. ARM 启动流程 1. 各种类型开发板启动流程 ( 1 ) 2440 开发板启动流程简介 ( ① Nand Flash 拷贝 4 KB -> SRAM 垫脚石 | ② PC 指向 ...
- 读《移山之道》 去“移山”
软件工程课老师让我们选一本教材,分别是<代码大全>.<快速软件开发>.<移山之道> .作为初入茅庐的人,对三本书没有先验知识的情况下,对比了这三本书,最后选择了&l ...
- 操作系统作业调度算法c语言,操作系统课程设计报告电梯调度算法c语言实现.doc...
操作系统课程设计报告电梯调度算法c语言实现 操作系统课程设计报告电梯调度算法c语言实现 :调度 算法 电梯 课程设计 操作系统 操作系统课程设计报告 模拟操作系统课程设计 写一个简单的操作系统 篇一: ...
- Linux C语言磁盘U盘容量读取、目录列表读取、文件夹大小读取
Linux C语言磁盘U盘容量读取.目录列表读取.文件夹大小读取C语言源代码 #include <stdio.h> #include <sys/statfs.h> #inclu ...
最新文章
- Phpcms V9手机门户设置教程:怎么用PC V9做手机网站
- 数据中心建设“优劣”在于这几个关键问题
- 交换机的端口工作模式
- 兼容ie跟谷歌上传文件
- Ubuntu 9.10下Nvidia官方最新190.42显卡驱动安装
- python文字识别算法_Python图像处理之图片文字识别(OCR)
- 【技术综述】你真的了解图像分类吗?
- ORACLE REPLACE函数
- CodeForces - 1551E Fixed Points(dp)
- 基于.NetCore3.1搭建项目系列 —— 认证授权方案之Swagger加锁
- Spring Boot 学习之旅
- Exploring Pyramids【动态规划——区间DP】
- ssm指的是什么_什么是RESTful?RESTfule风格又是啥?
- I/O----复制文本文件
- sencha touch Container控件 setRecord 与 setData的区别
- zen-Coding
- 《程序员修炼之道——从小工到专家》 读书笔记
- win10 悬浮日历_win10系统桌面上添加自带日历小工具的设置办法
- 计算机专业女生进电网,考入华北电力大学计算机专业,无缘国家电网,这是为什么?...
- 存储容量扩展的设计仿真实验