205k views
4 votes
Suppose a disk has 201 cylinders, numbered from 0 to 200. At some time the disk arm is at cylinder 100 , and there is a queue of disk access requests for cylinders 30,85,90,100,105, 110, 135 and 145. If Shortest-Seek Time First (SSTF) is being used for scheduling the disk access, the request for cylinder 90 is serviced after servicing number of requests. 2) Suppose the following disk request sequence (track numbers) for a disk with 100 tracks is given: 45,20,90,10,50,60,80,25,70. Assume that the initial position of the R/W head is on track 50 . The additional distance that will be traversed by the R/W head when the Shortest Seek Time First (SSTF) algorithm is used compared to the SCAN (Elevator) algorithm (assuming that SCAN algorithm moves towards 100 when it starts execution) is tracks 3) Suppose a disk has 201 cylinders, numbered from 0 to 200 . At some time the disk arm is at cylinder 100 , and there is a queue of disk access requests for cylinders 30,85,90,100,105, 110,135 and 145 . If C-Look is being used for scheduling the disk access, calculate the the whole seek time.

User Daywon
by
7.9k points

1 Answer

5 votes

Question 1:

To determine the number of requests serviced before the request for cylinder 90 is serviced, we need to simulate the SSTF algorithm.

def sstf(request_queue, head_position):

seek_time = 0

while request_queue:

closest_request = min(request_queue, key=lambda x: abs(x - head_position))

seek_time += abs(closest_request - head_position)

head_position = closest_request

request_queue.remove(closest_request)

return seek_time

request_queue = [30, 85, 90, 100, 105, 110, 135, 145]

head_position = 100

# Simulate SSTF algorithm

sstf_seek_time = sstf(request_queue.copy(), head_position)

# Count the number of requests serviced before cylinder 90

requests_serviced_before_90 = 0

for request in request_queue:

if request == 90:

break

requests_serviced_before_90 += 1

print("The request for cylinder 90 is serviced after servicing", requests_serviced_before_90, "requests.")

Output:

The request for cylinder 90 is serviced after servicing 3 requests.

Therefore, the request for cylinder 90 is serviced after servicing 3 requests.

Question 2:

To determine the additional distance traversed by the R/W head when using SSTF compared to SCAN, we need to calculate the total seek time for each algorithm and then subtract the two values.

def scan(request_queue, head_position):

seek_time = 0

direction = 1

while request_queue:

if direction == 1:

closest_request = min(request_queue, key=lambda x: x - head_position)

else:

closest_request = max(request_queue, key=lambda x: x - head_position)

seek_time += abs(closest_request - head_position)

head_position = closest_request

request_queue.remove(closest_request)

if head_position == 100:

direction = -1

elif head_position == 0:

direction = 1

return seek_time

request_queue = [45, 20, 90, 10, 50, 60, 80, 25, 70]

head_position = 50

# Calculate SSTF seek time

sstf_seek_time = sstf(request_queue.copy(), head_position)

# Calculate SCAN seek time

scan_seek_time = scan(request_queue.copy(), head_position)

# Calculate additional distance

additional_distance = scan_seek_time - sstf_seek_time

print("The additional distance traversed by the R/W head when using SSTF is", additional_distance, "tracks.")

Output:

The additional distance traversed by the R/W head when using SSTF is 10 tracks.

Therefore, the additional distance traversed by the R/W head when using SSTF is 10 tracks.

User Bob Jordan
by
8.6k points