SCAN和C-SCAN磁盘调度

时间:2022-09-06 13:09:54

http://www.slideshare.net/myrajendra/scan-scheduling-50-1 http://www.slideshare.net/myrajendra/c-scan-scheduling-50-2

In the above links both SCAN and C-SCAN was explained with a same example but why does SCAN moves towards left and C_SCAN moves towards right?

在上面的链接中,SCAN和C-SCAN都用相同的例子解释,但为什么SCAN向左移动而C_SCAN向右移动?

2 个解决方案

#1


The examples were constructed to try to show that SCAN will move both left and right to the next requested track, while CSCAN will only move right to the next requested track, and will skip requests when going left until it arrives at the leftmost/lowest numbered request.

构造示例以试图显示SCAN将向左和向右移动到下一个请求的轨道,而CSCAN将仅向右移动到下一个请求的轨道,并且在向左移动时将跳过请求直到它到达最左边/最低编号请求。

#2


Implementation of SCAN in java:

在java中实现SCAN:

package diskScheduling;
import java.util.*;
public class SCAN {

    public static int  callSCAN(int arr[],int init,int maxreq){
        /* In this algorithm head moves only in one direction and
         *  on reaching the boundary its reverses its direction 
         *  Here in this algorithm , we implement it move in forward direction first
         *  ,i.e towards higher track requests,then towards lower track request*/

        int sum=0,len=arr.length;

        //sorting the requests
        Arrays.sort(arr);

        //finding virtual location of init in the request array
        //binary search returns the index of search element if found 
        //else it returns -(insertion point) -1
        int pos=    Arrays.binarySearch(arr, init);

        pos=-pos-1;
//      System.out.println(pos);
        int left=pos-1,right=pos;

        //moving towards right side first in the array
        sum+=Math.abs(init-arr[right]);
        System.out.println(arr[right]);
        while(right<len-1){
            sum+=Math.abs(arr[right]-arr[right+1]);
            System.out.println(arr[right+1]);
            right++;
        }
        /* moving to maximum possible track request from
         *  where head will reverse its direction  */
        sum+=Math.abs(arr[len-1]-maxreq);
        System.out.println(maxreq);


        //now moving towards left direction .
        sum+=Math.abs(maxreq-arr[left]);
        System.out.println(arr[left]);

        while(left!=0){
            sum+=Math.abs(arr[left]-arr[left-1]);
            System.out.println( arr[left-1]);
            left--;
        }
        return sum;
    }
    public static void main(String[] args) {
        //maxreq maximum possible disk request
        int maxreq = 200;
        //request array
        int arr[]={98,183,37,122,14,124,65,67};
        // disk head starts at init
        int init=53;
        int res=callSCAN(arr,init,maxreq);
        System.out.println("Total Head Movement= "+res);
    }

}

#1


The examples were constructed to try to show that SCAN will move both left and right to the next requested track, while CSCAN will only move right to the next requested track, and will skip requests when going left until it arrives at the leftmost/lowest numbered request.

构造示例以试图显示SCAN将向左和向右移动到下一个请求的轨道,而CSCAN将仅向右移动到下一个请求的轨道,并且在向左移动时将跳过请求直到它到达最左边/最低编号请求。

#2


Implementation of SCAN in java:

在java中实现SCAN:

package diskScheduling;
import java.util.*;
public class SCAN {

    public static int  callSCAN(int arr[],int init,int maxreq){
        /* In this algorithm head moves only in one direction and
         *  on reaching the boundary its reverses its direction 
         *  Here in this algorithm , we implement it move in forward direction first
         *  ,i.e towards higher track requests,then towards lower track request*/

        int sum=0,len=arr.length;

        //sorting the requests
        Arrays.sort(arr);

        //finding virtual location of init in the request array
        //binary search returns the index of search element if found 
        //else it returns -(insertion point) -1
        int pos=    Arrays.binarySearch(arr, init);

        pos=-pos-1;
//      System.out.println(pos);
        int left=pos-1,right=pos;

        //moving towards right side first in the array
        sum+=Math.abs(init-arr[right]);
        System.out.println(arr[right]);
        while(right<len-1){
            sum+=Math.abs(arr[right]-arr[right+1]);
            System.out.println(arr[right+1]);
            right++;
        }
        /* moving to maximum possible track request from
         *  where head will reverse its direction  */
        sum+=Math.abs(arr[len-1]-maxreq);
        System.out.println(maxreq);


        //now moving towards left direction .
        sum+=Math.abs(maxreq-arr[left]);
        System.out.println(arr[left]);

        while(left!=0){
            sum+=Math.abs(arr[left]-arr[left-1]);
            System.out.println( arr[left-1]);
            left--;
        }
        return sum;
    }
    public static void main(String[] args) {
        //maxreq maximum possible disk request
        int maxreq = 200;
        //request array
        int arr[]={98,183,37,122,14,124,65,67};
        // disk head starts at init
        int init=53;
        int res=callSCAN(arr,init,maxreq);
        System.out.println("Total Head Movement= "+res);
    }

}