C-SCAN磁盘调度算法详细介绍

2021年3月10日16:09:06 发表评论 530 次浏览

1. 让Request数组表示一个数组, 该数组存储已按其到达时间的升序请求的音轨的索引。 "磁头"是磁盘磁头的位置。
2. 磁头仅在从0到磁盘大小的正确方向上服务。
3. 在向左移动时, 请勿维修任何轨道。
4. 当我们到达起点(左端)时, 反转方向。
5. 沿正确方向移动时, 它为所有轨道提供一对一服务。
6. 沿正确方向移动时, 计算轨道与头部的绝对距离。
7. 以此距离增加总寻道数。
8. 当前服务的轨道位置现在变为新的头位置。
9. 转到步骤6, 直到到达磁盘的右端。
10. 如果我们到达磁盘的右端, 请反转方向, 然后转到步骤3, 直到未维修请求数组中的所有轨道。

Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}

Output:
Total number of seek operations = 190
Seek Sequence is
60
79
92
114
176
199
0
11
34
41

= (60-50)+(79-60)+(92-79)
+(114-92)+(176-114)+(199-176)+(199-0)
+(11-0)+(34-11)+(41-34)

#include <bits/stdc++.h>
using namespace std;

// Code by Vikram Chaurasia

// C++ program to demonstrate
// C-SCAN Disk Scheduling algorithm

int size = 8;
int disk_size = 200;

{
int seek_count = 0;
int distance, cur_track;
vector<int> left, right;
vector<int> seek_sequence;

// appending end values
// which has to be visited
// before reversing the direction
left.push_back(0);
right.push_back(disk_size - 1);

// tracks on the left of the
// head will be serviced when
// once the head comes back
// to the beggining (left end).
for (int i = 0; i < size; i++) {
left.push_back(arr[i]);
right.push_back(arr[i]);
}

// sorting left and right vectors
std::sort(left.begin(), left.end());
std::sort(right.begin(), right.end());

// first service the requests
// on the right side of the
for (int i = 0; i < right.size(); i++) {
cur_track = right[i];
// appending current track to seek sequence
seek_sequence.push_back(cur_track);

// calculate absolute distance

// increase the total count
seek_count += distance;

// accessed track is now new head
}

// once reached the right end

// Now service the requests again
// which are left.
for (int i = 0; i < left.size(); i++) {
cur_track = left[i];

// appending current track to seek sequence
seek_sequence.push_back(cur_track);

// calculate absolute distance

// increase the total count
seek_count += distance;

// accessed track is now the new head
}

cout << "Total number of seek operations = "
<< seek_count << endl;

cout << "Seek Sequence is" << endl;

for (int i = 0; i < seek_sequence.size(); i++) {
cout << seek_sequence[i] << endl;
}
}

// Driver code
int main()
{

// request array
int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };

return 0;
}
Output: