0% found this document useful (0 votes)
4 views

scan_disk_scheduling_code

The document contains a C program that implements the SCAN disk scheduling algorithm. It includes functions for calculating seek time, copying arrays, sorting requests, and processing disk requests based on the current position of the disk arm. The program prompts the user for input regarding disk track limits, number of requests, and the current position, then outputs the order of servicing requests and total head movements.

Uploaded by

asishpunoff231
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

scan_disk_scheduling_code

The document contains a C program that implements the SCAN disk scheduling algorithm. It includes functions for calculating seek time, copying arrays, sorting requests, and processing disk requests based on the current position of the disk arm. The program prompts the user for input regarding disk track limits, number of requests, and the current position, then outputs the order of servicing requests and total head movements.

Uploaded by

asishpunoff231
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>

int getSeekTime(int a, int b){


if(a > b)
return a - b;
return b - a;
}

void copy(int arr[], int temp[], int n){


for(int i = 0; i < n; i++)
temp[i] = arr[i];
}

void sort(int arr[], int n){


int temp;
for(int i = 0; i < n - 1; i++){
for(int j = 0; j < n - i - 1; j++){
if(arr[j] > arr[j + 1]){
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}

int reqIndex(int arr[], int n, int p){


for(int i = 0; i < n; i++){
if(arr[i] >= p)
return i;
}
return n;
}

void scan(int arr[], int n, int p, int max){


printf("\nSCAN Disk Scheduling\n");
int seekTime = 0, temp[n], i;
copy(arr, temp, n);
sort(temp, n);
int index = reqIndex(temp, n, p);

seekTime += getSeekTime(p, max);


printf("%d => ", p);
for(i = index; i < n; i++){
printf("%d => ", temp[i]);
p = temp[i];
}
printf("%d\n%d => ", max, max);
p = max;
for(i = index - 1; i >= 0; i--){
if(i != 0)
printf("%d => ", temp[i]);
else
printf("%d", temp[i]);
p = temp[i];
}
seekTime += getSeekTime(max, temp[0]);
printf("\nTotal Head Movements in SCAN = %d\n\n", seekTime);
}

void main(){
printf("DISK SCHEDULING - SCAN\n");
int n, i, max, p;
printf("Enter the disk track limit(max): ");
scanf("%d", &max);
printf("Enter the number of requests: ");
scanf("%d", &n);
printf("Enter the requests \n");
int arr[n];
for(i = 0; i < n; i++){
scanf("%d", &arr[i]);
}
printf("Enter the current position of disk arm: ");
scanf("%d", &p);

scan(arr, n, p, max);
}

You might also like