0% found this document useful (0 votes)
9 views4 pages

Program-10_SCAN disk

Uploaded by

sreelakshmikn33
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)
9 views4 pages

Program-10_SCAN disk

Uploaded by

sreelakshmikn33
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/ 4

Department of Computer Science Engineering – ( Data Science)

Program 9: Develop a C program to simulate SCAN disk scheduling algorithm.

Disk Scheduling Operating System

 A process needs two type of time, CPU time and IO time. For I/O, it requests the Operating
system to access the disk.
 However, the operating system must be fare enough to satisfy each request and at the same time,
operating system must maintain the efficiency and speed of process execution.
 The technique that operating system uses to determine the request which is to be satisfied next is
called disk scheduling.
 Seek Time: Seek time is the time taken in locating the disk arm to a specified track where the
read/write request will be satisfied.

Scan Algorithm
 It is also called as Elevator Algorithm.
 In this algorithm, the disk arm moves into a particular direction till the end, satisfying all the
requests coming in its path,and then it turns backand moves in the reverse direction satisfying
requests coming in its path.
 It works in the way an elevator works, elevator moves in a direction completely till the last floor
of that direction and then turns back
 Example: Consider a disk queue with requests for I/O to blocks on cylinders 98, 183, 41, 122,
14, 124, 65, 67. The SCAN scheduling algorithm is used. The head is initially at cylinder
number 53 moving towards larger cylinder numbers on its servicing pass. The cylinders are
numbered from 0 to 199.

Operating Systems Lab[BCS303] 1


Department of Computer Science Engineering – ( Data Science)

Program
#include<stdio.h>
int main()
{
int queue[20],n,head,i,j,k,seek=0,max,diff,temp,queue1[20],queue2[20],
temp1=0,temp2=0;
float avg;
printf("Enter the max range of disk\n");
scanf("%d",&max);
printf("Enter the initial head position\n");
scanf("%d",&head);
printf("Enter the size of queue request\n");
scanf("%d",&n);
printf("Enter the queue of disk positions to be read\n");
for(i=1;i<=n;i++)
{
scanf("%d",&temp);
if(temp>=head)
{
queue1[temp1]=temp;
temp1++;
}
else
{
queue2[temp2]=temp;
temp2++;
}
}

Operating Systems Lab[BCS303] 2


Department of Computer Science Engineering – ( Data Science)
for(i=0;i<temp1-1;i++)
{
for(j=i+1;j<temp1;j++)
{
if(queue1[i]>queue1[j])
{
temp=queue1[i];
queue1[i]=queue1[j];
queue1[j]=temp;
}
}
}
for(i=0;i<temp2-1;i++)
{
for(j=i+1;j<temp2;j++)
{
if(queue2[i]<queue2[j])
{
temp=queue2[i];
queue2[i]=queue2[j];
queue2[j]=temp;
}
}
}
for(i=1,j=0;j<temp1;i++,j++)
queue[i]=queue1[j];

queue[i]=max;
for(i=temp1+2,j=0;j<temp2;i++,j++)
queue[i]=queue2[j];
queue[i]=0;
queue[0]=head;

Operating Systems Lab[BCS303] 3


Department of Computer Science Engineering – ( Data Science)
for(j=0;j<=n+1;j++)
{
diff=abs(queue[j+1]-queue[j]);
seek+=diff;
printf("Disk head moves from %d to %d with seek %d \n", queue[j], queue[j+1], diff);
}
printf("Total seek time is %d\n",seek);
avg=seek/(float)n;
printf("Average seek time is %f\n",avg);
return 0;
}

Sample Output
Enter the max range of disk
200
Enter the initial head position
50
Enter the size of queue request
7
Enter the queue of disk positions to be read
30 45 50 57 78 150 180
Disk head moves from 55 to 57 with seek 2
Disk head moves from 57 to 78 with seek 21
Disk head moves from 78 to 150 with seek 72
Disk head moves from 150 to 180 with seek 30
Disk head moves from 180 to 200 with seek 20
Disk head moves from 200 to 50 with seek 150
Disk head moves from 50 to 45 with seek 5
Disk head moves from 45 to 30 with seek 15
Disk head moves from 30 to 0 with seek 30
Total seek time is 345
Average seek time is 49.285713

Operating Systems Lab[BCS303] 4

You might also like