0
0
Operating Systemsknowledge~6 mins

SSTF (Shortest Seek Time First) in Operating Systems - Full Explanation

Choose your learning style9 modes available
Introduction
Imagine waiting for a library assistant to fetch books from different shelves. The order in which the assistant picks books can make the wait longer or shorter. SSTF helps decide which request to handle next to reduce waiting time in disk operations.
Explanation
Purpose of SSTF
SSTF is a method used by operating systems to decide the order of disk read/write requests. It picks the request closest to the current position of the disk head to minimize movement. This reduces the time the disk takes to access data.
SSTF chooses the nearest request to reduce disk head movement and access time.
How SSTF Works
When multiple requests are waiting, SSTF calculates the distance from the current head position to each request. It then selects the request with the shortest distance. This process repeats after each request is served, always picking the closest next request.
SSTF always selects the next request with the shortest seek distance from the current head position.
Advantages of SSTF
By reducing the distance the disk head moves, SSTF can improve overall performance compared to simple methods like First-Come-First-Served. It lowers average waiting time and speeds up data access in many cases.
SSTF improves disk efficiency by lowering average seek time compared to simpler scheduling methods.
Limitations of SSTF
SSTF can cause some requests to wait too long if they are far from the current head position, leading to a problem called starvation. It also does not guarantee the shortest total movement over all requests, only the next closest one.
SSTF may cause starvation for distant requests and does not always minimize total disk movement.
Real World Analogy

Imagine a librarian fetching books from shelves arranged in a line. Instead of fetching books in the order requested, the librarian always picks the book closest to their current position to save walking time. However, some books far away might have to wait longer.

Purpose of SSTF → Librarian choosing the closest book to fetch next to save walking time
How SSTF Works → Librarian checking distances to all requested books and picking the nearest one
Advantages of SSTF → Librarian reducing total walking distance compared to fetching books in request order
Limitations of SSTF → Books far away waiting longer because librarian keeps picking closer books
Diagram
Diagram
Current Head Position
      ↓
┌─────┬─────┬─────┬─────┬─────┬─────┐
│  1022202406  │
└─────┴─────┴─────┴─────┴─────┴─────┘
Requests: 2, 6, 10, 20, 22, 40
SSTF picks 10 first (closest), then 6, then 2, and so on.
This diagram shows disk requests on a line with the current head position and the order SSTF picks requests based on shortest distance.
Key Facts
SSTFA disk scheduling algorithm that selects the request closest to the current head position.
Seek TimeThe time it takes for the disk head to move to the track where data is stored.
StarvationA situation where some requests wait indefinitely because others are always closer.
Disk HeadThe part of the disk that reads or writes data by moving over tracks.
Code Example
Operating Systems
def sstf_schedule(requests, head):
    requests = requests.copy()
    order = []
    while requests:
        distances = {r: abs(r - head) for r in requests}
        closest = min(distances, key=distances.get)
        order.append(closest)
        head = closest
        requests.remove(closest)
    return order

# Example usage
requests = [10, 22, 20, 2, 40, 6]
head = 15
print(sstf_schedule(requests, head))
OutputSuccess
Common Confusions
SSTF always gives the fastest overall disk access.
SSTF always gives the fastest overall disk access. SSTF only picks the closest next request, but this does not guarantee the shortest total movement or fastest overall completion.
SSTF prevents all requests from waiting too long.
SSTF prevents all requests from waiting too long. SSTF can cause starvation where some requests far from the head position wait much longer than others.
Summary
SSTF reduces disk seek time by always choosing the closest request next.
It improves performance but can cause some requests to wait too long (starvation).
SSTF does not guarantee the shortest total disk movement, only the next shortest seek.