![]() |
VOOZH | about |
C-LOOK Disk Scheduling Algorithm is an enhanced version of both SCAN as well as LOOK disk scheduling algorithms. This algorithm also uses the idea of wrapping the tracks as a circular cylinder as the C-SCAN Algorithm but the seek time is better than the C-SCAN algorithm. We know that C-SCAN is used to avoid starvation and services all the requests more uniformly, the same goes for C-LOOK.
In this algorithm, the head services request only in one direction(either left or right) until all the requests in this direction are not serviced and then jumps back to the farthest request in the other direction and services the remaining requests which gives a better uniform servicing as well as avoids wasting seek time for going till the end of the disk.
In this article, we will see given an array of disk track numbers and initial head position, our task is to find the total number of seek operations to access all the requested tracks if the C-LOOK disk scheduling algorithm is used. Also, write a program to find the seek sequence using the C-LOOK disk scheduling algorithm.
Step 1: Let the Request array represents an array storing indexes of the tracks that have been requested in ascending order of their time of arrival and the head is the position of the disk head.
Step 2: The initial direction in which the head is moving is given and it services in the same direction.
Step 3: The head services all the requests one by one in the direction it is moving.
Step 4: The head continues to move in the same direction until all the requests in this direction have been serviced.
Step 5: While moving in this direction, calculate the absolute distance of the tracks from the head.
Step 6: Increment the total seek count with this distance.
Step 7: Currently serviced track position now becomes the new head position.
Step 8: Go to step 5 until we reach the last request in this direction.
Step 9: If we reach the last request in the current direction then reverse the direction and move the head in this direction until we reach the last request that is needed to be serviced in this direction without servicing the intermediate requests.
Step 10: Reverse the direction and go to step 3 until all the requests have not been serviced.
Example:
Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50
Direction = right (Moving from left to right) Output:
Initial position of head: 50
Total number of seek operations = 321
Seek Sequence is 60, 79 , 92 , 114 , 176, 11 , 34, 41
The following chart shows the sequence in which requested tracks are serviced using C-LOOK.
Therefore, the total seek count = (60 - 50) + (79 - 60) + (92 - 79) +
(114 - 92) + (176 - 114) + (176 - 11) + (34 - 11) + (41 - 34) = 321
The implementation of the C-LOOK algorithm is given below. The distance variable is used to store the absolute distance between the head and the current track position, disk_size is the size of the disk. Vectors left and right store all the request tracks on the left-hand side and the right-hand side of the initial head position respectively.
Output:
Initial Position of Head: 50
Total Number of Seek Operations: 321
Seek Sequence: 60, 79, 92, 114, 176, 11, 34, 41