Implementation of Disk Scheduling Algorithms - FCFS,: SSTF, Cscan
Implementation of Disk Scheduling Algorithms - FCFS,: SSTF, Cscan
Implementation of Disk Scheduling Algorithms - FCFS,: SSTF, Cscan
TITLE: Deadlock
AIM: Implementation of Disk scheduling algorithms
OUTCOME: Student can understand working of an OS as a manager for file, memory and
I/O system.
SSTF Algorithm:
1. Let Request array represents an array storing indexes of tracks that have been
requested. ‘head’ is the position of disk head.
2. Find the positive distance of all tracks in the request array from head.
3. Find a track from requested array which has not been accessed/serviced yet and has
minimum distance from head.
4. Increment the total seek count with this distance.
5. Currently serviced track position now becomes the new head position.
Solution-
2. Consider a disk system with 100 cylinders. The requests to access the
cylinders occur in following sequence-
4, 34, 10, 7, 19, 73, 2, 15, 6, 20
Solution-
Write full code for all algorithm along with output and
screen shot.
FCFS:
CODE:
#include <conio.h>
#include <stdio.h>
int main()
{
int i, j, sum = 0, n;
int ar[20], tm[20];
int disk;
printf("enter number of location\t");
scanf("%d", &n);
printf("enter position of head\t");
scanf("%d", &disk);
printf("enter elements of disk queue\n");
for (i = 0; i < n; i++)
{
scanf("%d", &ar[i]);
tm[i] = disk - ar[i];
if (tm[i] < 0)
{
tm[i] = ar[i] - disk;
}
disk = ar[i];
sum = sum + tm[i];
}
/*for(i=0;i<n;i++)
{
printf("\n%d",tm[i]);
} */
printf("\nmovement of total cylinders %d", sum);
Department of Electronics and Telecommunication Engineering
OUTPUT:
SSTF:
CODE:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
// 1000 is for max
// you can use any number
RQ[index]=1000;
count++;
}