# SCAN (Elevator) Disk Scheduling Algorithm

In the Operating System, the requests from the input or output of the programs or applications are handled by Disk scheduling algorithms. The System receives countless numbers of requests from different programs and only one request can be processed at a time by the system and all other requests has to wait in queue. The major work of disk scheduling is to increase the performance of the system by reducing seek time, rotating latency, and transfer time. For these processes, different algorithms are used and one among them is SCAN (Elevator).

## Scan Disk Scheduling Algorithm

The Scan Disk Scheduling algorithm is also called the elevator algorithm because of its working fashion. The Elevator moves up and down based on the requests from different persons on different floors. When the elevator reaches either the last floor or the ground floor, it will change its direction and starts moving in the opposite direction.

Similar to the above functioning, the disk arm moves back and forth across the disk based on servicing requests for tracks along the way.

### Characteristics of Scan Disk Scheduling Algorithm

• The requests at the middle range are serviced more and those arriving behind the disk arm will have to wait.

• This algorithm is simple.

• It has no starvation because processes are allocated with resources as the disk moves continuously.

• It is far better than the First Come First Serve algorithm.

#### Example of SCAN Disk Scheduling Algorithm −

Algorithm

Step 1 The array has the elements that have requested resources from different processes in ascending order based on arrival time.

Step 2 The disk arm starts from one end of the disk and moves towards the other end.

Step 3 When the disk moves in this direction, it will service all tracks one by one based on the request.

Step 4 Then calculate the total distance traveled from the head.

Step 5 The new position is identified by the currently serviced request

Step 6 Then step 3 is repeated when it reaches one end of the disk.

Step 7 When the endpoint is reached, it will reverse the direction and go back to step 2 when the entire request has been serviced.

### Approach: C Program to implement SCAN Disk scheduling algorithm

Program,Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define size 10
#define disk_size 200
int comp(const void * l, const void * n) {
return (*(int*)l - *(int*)n);
}
void SCAN(int arr[], int head, char* dn){
int seek_num = 0;
int dt, cur_track;
int leftside[size], rightside[size];
int seek_seq[size + 3];
int m_scan = 0, s_scan = 0;
if (strcmp(dn, "leftside") == 0)
leftside[m_scan++] = 0;
else if (strcmp(dn, "rightside") == 0)
rightside[s_scan++] = disk_size - 1;
for (int p_s = 0; p_s < size; p_s++) {
leftside[m_scan++] = arr[p_s];
rightside[s_scan++] = arr[p_s];
}
qsort(leftside, m_scan, sizeof(int), comp);
qsort(rightside, s_scan, sizeof(int), comp);
int go = 2;
int ind = 0;
while (go--) {
if (strcmp(dn, "leftside") == 0) {
for (int p_s = m_scan - 1; p_s >= 0; p_s--) {
cur_track = leftside[p_s];
seek_seq[ind++] = cur_track;
seek_num += dt;
}
dn = "rightside";
}
else if (strcmp(dn, "rightside") == 0) {
for (int p_s = 0; p_s < s_scan; p_s++) {
cur_track = rightside[p_s];
seek_seq[ind++] = cur_track;
seek_num += dt;
}
dn = "leftside";
}
}
printf("Num of seek process = %d", seek_num);
printf("Sequence is");
for (int p_s = 0; p_s < ind; p_s++) {
printf("%d", seek_seq[p_s]);
}
}
int main(){
int arr[size] = { 126, 90, 14, 50, 25, 42, 51, 78, 102, 100 };
char dn[] = "leftside";
return 0;
}


Output

Num of seek process = 168
Sequence is
25
14
0
50
51
78
90
100
102
126


## Conclusion

The concept of SCAN disk scheduling is depicted in this article along with an example. It is used to schedule the programs based on the request from direct access. Direct access is the parameter that takes more time in the operating system and its main purpose is to minimize the seek time and transfer time and increase its performance.

Updated on: 17-Jul-2023

1K+ Views