Introduction to SSTF disk scheduling :

SSTF stands for Shortest Time First which very uses full of learning about how the disk drive manages the data having the shortest seek time.



Algorithm of the SSTF is given below:-

  • Find the positive distance of all tracks in the request array from the head.
  • Find a track from the requested array which has not been accessed/serviced yet and has a minimum distance from the head.
  • Increment the total seek count with this distance.
  • Currently serviced track position now becomes the new head position.
  • Go to step 2 until all tracks in request array have not been serviced.

C program for Shortest Seek Time Next Disk Scheduling Algorithm 



#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
    int queue[100], t[100], head, seek = 0, n, i, j, temp;
    float avg;
    // clrscr();
    printf("*** SSTF Disk Scheduling Algorithm ***\n");
    printf("Enter the size of Queue\t");
    scanf("%d", &n);
    printf("Enter the Queue\t");
    for (i = 0; i < n; i++)
    {
        scanf("%d", &queue[i]);
    }
    printf("Enter the initial head position\t");
    scanf("%d", &head);
    for (i = 1; i < n; i++)
        t[i] = abs(head - queue[i]);
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if (t[i] > t[j])
            {
                temp = t[i];
                t[i] = t[j];
                t[j] = temp;
                temp = queue[i];
                queue[i] = queue[j];
                queue[j] = temp;
            }
        }
    }
    for (i = 1; i < n - 1; i++)
    {
        seek = seek + abs(head - queue[i]);
        head = queue[i];
    }
    printf("\nTotal Seek Time is%d\t", seek);
    avg = seek / (float)n;
    printf("\nAverage Seek Time is %f\t", avg);
    return 0;
}

You May Also Like:

C Program for SCAN disk scheduling algorithm 

C program for First Come First Serve (FCFS) disk scheduling algorithm | C Programming


C program for Shortest Seek Time Next Disk Scheduling Algorithm | C Programming


C++ program for LOOK Disk Scheduling Algorithm | C++ Programming


C Program for C-SCAN Disk Scheduling Algorithm | C Programming


C++ Program For C-LOOK Disk Scheduling Algorithm | C++ Programming


Share To:

Arogya Thapa Magar

Post A Comment:

1 comments so far,Add yours