C-Program of SSTF (Short seek time first )Disk scheduling Algorithms in operating system (OS).

  What is SSTF disk scheduling:-

                                                        Shortest seek time first (SSTF) algorithm selects the disk I/O request which requires the least disk arm movement from its current position regardless of the direction. It reduces the total seek time as compared to FCFS.

Example:-: Given the following queue — 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head initially at the track 50 and the tail track being at 199.

Advantage:-
  1. seek time reduces as compaired to the FCFS
  2. Less waiting time and response time 
  3. Increase throughput.
Disadvantage:-
  1. starvation occurred


Code:-

#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf(“Enter the number of Requestsn”);
scanf(“%d”,&n);
printf(“Enter the Requests sequencen”);
for(i=0;i<n;i++)
scanf(“%d”,&RQ[i]);
printf(“Enter initial head positionn”);
scanf(“%d”,&initial);
// logic for sstf disk scheduling
/* loop will execute until all process is completed*/
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];
// 1000 is for max
// you can use any number
RQ[index]=1000;
count++;
}
printf(“Total head movement is %d”,TotalHeadMoment);
return 0;
}

Output:-

Enter the number of Request
8
Enter Request Sequence
95 180 34 119 11 123 62 64
Enter initial head Position
50
Total head movement is 236


Must Visit:-
                      Program of disk scheduling algorithm

Recommended Post:

Hackerearth Problems:-

Data structure:-

Key points:-

 MCQs:-

One thought on “C-Program of SSTF (Short seek time first )Disk scheduling Algorithms in operating system (OS).

Leave a Reply

Your email address will not be published.