Program to simulate SSTF Disk Scheduling Algorithm


No matter which direction the disk arm must move from its current position, the shortest search time first (SSTF) algorithm chooses the disk I/O request. Compared to FCFS, it decreases the overall seek time.

#include <stdio.h>
#include <stdlib.h>
int main(){
    int RQ[100], i, n, TotalHeadMoment = 0, initial, count = 0;
    printf("Enter the number of Requests\n");
    scanf("%d", &n);
    printf("Enter the Requests sequence\n");
    for (i = 0; i < n; i++)
        scanf("%d", &RQ[i]);
    printf("Enter initial head position\n");
    scanf("%d", &initial);
    while (count != n){
        int min = 1000, d, index;
        for (i = 0; i < n; i++){
            d = abs(RQ[i] - initial);
            if (min > d){
                min = d;
                index = i;
        TotalHeadMoment = TotalHeadMoment + min;
        initial = RQ[index];
        RQ[index] = 1000;
    printf("Total head movement is %d \n", TotalHeadMoment);
    return 0;


Learn about: Operating System

Source code on GitHub:

Sudeep Mishra

Sudeep Mishra


%d bloggers like this: