日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

移臂调度算法c语言,磁盘移臂调度算法实验

發布時間:2023/12/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 移臂调度算法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语言,磁盘移臂调度算法实验的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 亚洲天堂色图 | 久久视精品 | 欧美人人爽 | 肉丝肉足丝袜一区二区三区 | 亚洲熟女乱综合一区二区三区 | 乱人伦xxxx国语对白 | 日本a级在线 | 台湾极品xxx少妇 | 国产一区在线免费观看 | 97免费在线 | 免费观看污网站 | 男女啪啪免费看 | 免费高清成人 | 婷婷六月天在线 | 久久性生活视频 | 又黄又高潮的视频 | 一区二区三区精品在线 | 国产精品sm调教免费专区 | 国产精品wwww | 国产无遮挡a片又黄又爽 | youjizz韩国 | 麻豆精品国产传媒mv男同 | 中国毛片在线观看 | 自拍天堂 | 久久久久国产精品午夜一区 | 日韩成人在线播放 | 国产麻豆一区二区 | 亚洲福利精品视频 | 欧美性猛交xx | 美女隐私直播 | 黄色香港三级三级三级 | 奇米四色网 | 娇小6一8小毛片 | a毛片成人| 黄色草逼网站 | 91美女诱惑 | 亚洲乱码精品久久久久 | 国产高潮av | 狠狠操免费视频 | 精品人妻一区二区三区蜜桃 | h视频在线免费观看 | 久久久久久久久蜜桃 | 国产欧美又粗又猛又爽 | 成人中文在线 | 污视频网站在线播放 | 欧美无砖砖区免费 | 日韩精品一区二区三区不卡在线 | 欧美黑人欧美精品刺激 | 福利视频一区二区三区 | 亚洲三级在线看 | 91视频在线观看 | 日本美女日批视频 | 亚洲欧美另类在线观看 | 五月婷婷综合色 | 国产精品久久久影院 | 91肉色超薄丝袜脚交一区二区 | www.四虎. | 麻豆影视在线 | 精品视频一二区 | 中文字幕88页 | 久久久国 | 男女做爰猛烈吃奶啪啪喷水网站 | 国产无遮挡又黄又爽免费视频 | 超碰caopeng | 国产精品电影一区二区三区 | 亚洲伊人婷婷 | 九九热免费在线视频 | 国产又粗又猛又黄视频 | 亚洲精品视频在线看 | 久久久久久五月天 | 欧美日韩色图片 | 女大学生的家政保姆初体验 | 亚洲精品国产成人无码 | 日本中文在线观看 | 欧美视频观看 | 精品少妇一区二区三区密爱 | 国产精品丝袜视频无码一区69 | 放荡的少妇2欧美版 | www欧美视频| 一级片视频免费 | 粉嫩欧美一区二区三区 | 欧美午夜激情影院 | 亚洲精品在线免费 | 欧美性视频播放 | 中文字幕一区二区三区精彩视频 | 素人av在线 | a视频免费| 伊人久久免费 | 日本aaa视频 | 精品少妇人妻av一区二区三区 | 青青草福利视频 | 欧美日韩高清一区二区三区 | a级片毛片| 久久精品aⅴ无码中文字字幕重口 | 日韩欧美精品一区 | 特级精品毛片免费观看 | 奇米7777| 国产a免费 | 色av免费|