Let us learn how to implement shortest seek time first algorithm in C programming with its explanation, output, advantages, disadvantages and much more.
What is Shortest Seek Time First Disk Scheduling Algorithm?
The shortest seek time first is commonly abbreviated as SSTF. It is also popularly known as shortest seek first algorithm.
The SSTF disk scheduling algorithm is a secondary storage scheduling algorithm which enables to determine the motion of the disk’s arm and the disk head in servicing read and write requests.
This algorithm helps to determine which job is nearest to the current head position with minimum seek time, and then services that job next.
In the SSTF algorithm, the jobs having the shortest seek time are executed first. Therefore, the seek time of each job is pre-calculated in the job queue and every job is scheduled according to its seek time.
This enables the job nearest to the disk arm to get executed first. It also has a better average response time and throughput as compared to the FCFS scheduling algorithm.
Advantages
- Reduced total seek time as compared to FCFS algorithm
- Increased throughput time
- Decreased average response time
Disadvantages
- There are high chances of starvation if the seek time is higher than the incoming jobs
- Switching the directions may slow down the process
- There are chances of overheads.
- This algorithm is not the most optimal one
Note: This C program to implement SSTF algorithm is compiled with GNU GCC compiler using CodeLite IDE on Microsoft Windows 10 operating system.
C Program For Shortest Seek Time First 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 | #include<stdio.h> struct head { int num; int flag; }; int main() { struct head h[33]; int array_1[33], array_2[33]; int count = 0, j, x, limit, minimum, location, disk_head, sum = 0; printf("\nEnter 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"); while(count < limit) { scanf("%d", &h[count].num); h[count].flag = 0; count++; } for(count = 0; count < limit; count++) { x = 0; minimum = 0; location = 0; for(j = 0; j < limit; j++) { if(h[j].flag == 0) { if(x == 0) { array_1[j] = disk_head - h[j].num; if(array_1[j] < 0) { array_1[j] = h[j].num - disk_head; } minimum = array_1[j]; location = j; x++; } else { array_1[j] = disk_head - h[j].num; if(array_1[j] < 0) { array_1[j] = h[j].num - disk_head; } } if(minimum > array_1[j]) { minimum = array_1[j]; location = j; } } } h[location].flag = 1; array_2[count] = h[location].num - disk_head; if(array_2[count] < 0) { array_2[count] = disk_head - h[location].num; } disk_head = h[location].num; } count = 0; while(count < limit) { sum = sum + array_2[count]; count++; } printf("\nTotal movements of the cylinders:\t%d", sum); return 0; } |
Output

If you have any doubts about the implementation of shortest seek first disk scheduling C program, let us know about it in the comment section. Find more about it here.