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:-
- seek time reduces as compared to the FCFS
- Less waiting time and response time
- Increase throughput.
Disadvantage:-
- starvation occurred
#include<bits/stdc++.h>
using namespace std;
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
cout<<"Enter the number of Requests\n";
cin>>n;
cout<<"Enter the Requests sequence\n";
for(i=0;i<n;i++)
cin>>RQ[i];
cout<<"Enter initial head position\n";
cin>>initial;
// logic for sstf disk scheduling
/* loop will execute until all process is completed*/
while(count!=n)
{
int min=INT_MAX,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]=INT_MAX;
count++;
}
cout<<"Total head movement is "<<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:-
See more:-
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation
0 Comments