Let us learn how to implement SCAN disk scheduling algorithm in C programming with its explanation, output, advantages, disadvantages and much more.
What Is Scan Disk Scheduling Algorithm?
The SCAN algorithm is a disk scheduling algorithm that helps in determining the motion of a disk’s arm and head in executing the read and write requests.
In the SCAN scheduling algorithm, the disk arm moves in a single direction and executes all the jobs coming in its way.
Once the disk arm reaches the end of that direction, it reverses the direction of scanning and executes all of the jobs arriving in its path.
The SCAN scheduling algorithm is also commonly known as Elevator algorithm, and this algorithm has a very high throughput. It also reduces the response time variance compared to the SSTF algorithm.
The elevator algorithm is performed by moving the read/write head back-and-forth to the innermost and outermost track.
There are multiple enhancements performed on the elevator algorithm which is depicted by the following algorithms:
- Circular SCAN algorithm
- LOOK algorithm
- Circular LOOK algorithm
Advantages
- Lower response time variance
- High throughput
- Average response time
Disadvantages
- There are chances of starvation of processes in some scenarios.
Note: This SCAN disk program in C is compiled with GNU GCC compiler using CodeLite IDE on Microsoft Windows 10 operating system.
C Program For SCAN Disk Scheduling Algorithm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include<stdio.h> #include<conio.h> void scan_algorithm(int left[], int right[], int count, int limit) { int arr[20]; int x = count - 1, y = count + 1, c = 0, d = 0, j; while(x > -1) { printf("\nX:\t%d", x); printf("\nLeft[X]:\t%d", left[x]); arr[d] = left[x]; x--; d++; } arr[d] = 0; while(y < limit + 1) { arr[y] = right[c]; c++; y++; } printf("\nScanning Order:\n"); for(j = 0; j < limit + 1; j++) { printf("\n%d", arr[j]); } } void division(int elements[], int limit, int disk_head) { int count = 0, p, q, m, x; int left[20], right[20]; for(count = 0; count < limit; count++) { if(elements[count] > disk_head) { printf("\nBreak Position:\t%d\n", elements[count]); break; } } printf("\nValue:\t%d\n", count); q = 1; p = 0; m = limit; left[0] = elements[0]; printf("\nLeft:\t%d", left[0]); while(q < count) { printf("\nElement[l] value:\t%d" , elements[q]); left[q] = elements[q]; printf("\nLeft:\t%d", left[q]); q++; printf("\nl:\t%d", q); } x = count; while(x < m) { right[p] = elements[x]; printf("\nRight:\t%d", right[p]); printf("\nElement:\t%d", elements[x]); p++; x++; } scan_algorithm(left, right, count, limit); } void sorting(int elements[], int limit) { int location, count, j, temp, small; for(count = 0; count < limit - 1; count++) { small = elements[count]; location = count; for(j = count + 1; j < limit; j++) { if(small > elements[j]) { small = elements[j]; location = j; } } temp = elements[location]; elements[location] = elements[count]; elements[count] = temp; } } int main() { int count, disk_head, elements[20], limit; printf("Enter total number of locations:\t"); scanf("%d", &limit); printf("\nEnter position of disk head:\t"); scanf("%d", &disk_head); printf("\nEnter elements of disk head queue\n"); for(count = 0; count < limit; count++) { printf("Element[%d]:\t", count + 1); scanf("%d", &elements[count]); } sorting(elements, limit); division(elements, limit, disk_head); getch(); return 0; } |
Output

If you have any doubts about the implementation of SCAN disk scheduling C program, let us know about it in the comment section. Find more about it on Wikipedia.
Thank you so much for this algorithm. I see that you have a good collection of quite a lot of CPU scheduling algorithms.
I see this is like a simulation of a hard disk how can a do this if posible on an actual hardrive having windows10 or debian?
Good!