0% found this document useful (0 votes)
15 views14 pages

EX12

Uploaded by

keerthi2k6
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)
15 views14 pages

EX12

Uploaded by

keerthi2k6
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/ 14

EX.NO:12(a) STIMULATES THE FCFS DISK SCHEDULING ALGORITHMS.

Date:

Aim:
Write a C Program to simulate the First Come First Serve Disk scheduling algorithms

Algorithm:

1. Start the process

2. Disk scheduling algorithm mainly used for memory-management in Operating System.

3. We know that a disk contains tracks, read-write head, and request queue. We’ll calculate the

total number of track movements

4. Get the input max range of disk ,size of queue request disk position and initial head position

5. Calculate the head movement in FCFS Disk scheduling Algorithm

6. Request array represents an array storing indexes of tracks that have been requested in

ascending order of their time of arrival. ‘head’ is the position of disk head.

7. Let us one by one take the tracks in default order and calculate the absolute distance of the

track from the head.

8. Increment the total seeks count with this distance.

9. Currently serviced track position now becomes the new head position.

10. Go to step 7 until all tracks in request array have not been serviced

11. Display the Results.

12. Stop the process.

13. Draw the disk algorithm flow chart.


Program:

#include<stdio.h>
#include<conio.h>
int main()
{
int queue[20],n,head,i,j,k,seek=0,max,diff;
float avg;
clrscr();
printf("Enter the max range of disk\n");
scanf("%d",&max);
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",&queue[i]);
printf("Enter the initial head position\n");
scanf("%d",&head);
queue[0]=head;
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/head move %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;
}
Output:
Result:

Thus the program was compiled and executed successfully


EX.NO:12(b) STIMULATES THE SCAN DISK SCHEDULING ALGORITHMS

Date:

Aim:
Write a C Program to simulate the SCAN Disk scheduling algorithms

Algorithm:

1. Start the process

2. Disk scheduling algorithm mainly used for memory-management in Operating System.

3. We know that a disk contains tracks, read-write head, and request queue. We’ll calculate the

total number of track movements

4. Get the input max range of disk ,size of queue request disk position and initial head position

5. Calculate the head movement in SCAN Disk scheduling Algorithm

6. Let the Request array represents an array storing indexes of tracks that have been requested in

ascending order of their time of arrival. ‘head’ is the position of the disk head.

7. Let direction represents whether the head is moving towards left or right.

8. In the direction in which the head is moving, service all tracks one by one.

9. Calculate the absolute distance of the track from the head.

10. Increment the total seeks count with this distance.

11. Currently serviced track position now becomes the new head position.

12. Go to step 8 until we reach one of the ends of the disk.

13. If we reach the end of the disk reverse the direction and go to step 2 until all tracks in the

request array have not been serviced.

14. Display the Results.

15. Stop the process

16. Draw the disk algorithm flow chart.


Program:

#include<stdio.h>
#include<conio.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;
clrscr();
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++;
}
}
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;
printf("head movement in forward direction");
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\head move %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;
}
Output:
Result:

Thus the program was compiled and executed successfully.


EX.NO:12(c) STIMULATES THE C SCAN DISK SCHEDULING ALGORITHMS

Date:

Aim:
Write a C Program to simulate the C SCAN Disk scheduling algorithms

Algorithm:

1. Start the process

2. Disk scheduling algorithm mainly used for memory-management in Operating System.

3. We know that a disk contains tracks, read-write head, and request queue. We’ll calculate the

total number of track movements

4. Get the input max range of disk ,size of queue request disk position and initial head position

5. Calculate the head movement in C SCAN Disk scheduling Algorithm

6. Let the Request array represents an array storing indexes of tracks that have been requested in

ascending order of their time of arrival. ‘head’ is the position of the disk head.

7. Let direction represents whether the head is moving towards left or right.

8. In the direction in which the head is moving, service all tracks one by one.

9. Calculate the absolute distance of the track from the head.

10. Increment the total seek count with this distance..

11. Currently serviced track position now becomes the new head position.

12. Go to step 8 until we reach one of the ends of the disk.

13. If we reach the end of the disk reverse the direction and go to step 7 until all tracks in the

request array have not been serviced.

14. Display the Results.

15. Stop the process.

16. Draw the disk algorithm flow chart.


Program:

#include<stdio.h>
#include<conio.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;
clrscr();
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++;
}
}
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;
queue[i+1]=0;
for(i=temp1+3,j=0;j<temp2;i++,j++)
queue[i]=queue2[j];
queue[0]=head;
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 /head move%d\n",queue[j],queue[j+1],diff);
}
Seek - =200;
printf("Total seek time is %d\n",seek);
avg=seek/(float)n;
printf("Average seek time is %f\n",avg);
return 0;
}
Output:
Result:

Thus the program was compiled and executed successfully.

You might also like