Write a program that implements the following disk-scheduling algorithms:
a. FCFS
b. SSTF
c. SCAN
d. C-SCAN
Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will be passed the initial position of the disk head (as a parameter on the command line) and report the total amount of head movement and total number of change of direction required by each algorithm under each of the following cases: a)The program will generate a random series of 1,000 cylinder requests and service them according to each of the algorithms listed above. b)The program will get a series of cylinder requests from the user and service them according to each of the algorithms listed above.
(a) FCFS
#include<stdio.h>
void main()
{
int h,i,rq[100],sum=0,n,j;
printf("\n Enter the length: ");
scanf("%d",&n);
printf("\n Enter the Head Value: ");
scanf("%d",&h);
//Input into Request Queue
printf("\n Enter the Request Queue ");
for(i=1;i<n+1;i++)
{
scanf("%d",&rq[i]);
}
//Scheduling - FCFS
rq[0]=h;
for(j=0;j<n;j++)
{
if(rq[j]>rq[j+1])
{
sum=(sum+(rq[j]-rq[j+1]));
}
else
{
sum=(sum+(rq[j+1]-rq[j]));
}
}
printf("\n Total Head movements are %d \n",sum);
}
(c) SCAN
#include <stdio.h>
void main()
{
int i,j,n,h,temp=0,dEnd=199,hPos,sum=0,count=1;
int rq[100],sq[100];
printf("\nEnter No. of Processes: ");
scanf("%d",&n);
printf("\nEnter Head value: ");
scanf("%d",&h);
//Enter value into Request Queue
printf("\nEnter elements into Request
Queue");
for(i=0;i<n;i++)
{
scanf("
%d",&rq[i]);
}
rq[i]=h;
rq[i+1]=0;
//Scheduling - SCAN
//Sort
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(rq[j]>rq[j+1])
{
temp=rq[j];
rq[j]=rq[j+1];
rq[j+1]=temp;
}
}
}
//Position
for(i=0;i<n;i++)
{
if(rq[i]>h)
{
hPos=i-1;
break;
}
}
//Schedule
sq[0]=h;
printf("\nScheduling\n");
if(h<(dEnd-h))
{
for(i=hPos;i>=0;i--)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
for(i=hPos+1;i<n;i++)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
}
else
{
for(i=hPos+1;i<n;i++)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
for(i=hPos;i>=0;i--)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
}
printf("\n Head Movements: ");
for(i=0;i<n;i++)
{
if(sq[i]>sq[i+1])
{
sum+=(sq[i]-sq[i+1]);
}
else
{
sum+=(sq[i+1]-sq[i]);
}
}
printf(" %d \n",sum);
}
(d) CSCAN
#include <stdio.h>
void main()
{
int i,j,n,h,temp=0,dEnd=199,hPos,sum=0,count=1;
int rq[100],sq[100];
printf("\nEnter No. of Processes: ");
scanf("%d",&n);
printf("\nEnter Head value: ");
scanf("%d",&h);
//Enter value into Request Queue
printf("\nEnter elements into Request
Queue");
for(i=0;i<n;i++)
{
scanf("
%d",&rq[i]);
}
rq[i]=h;
rq[i+1]=0;
//Scheduling - CSCAN
//Sort
for(i=0;i<n;i++)
{
for(j=0;j<n-1;j++)
{
if(rq[j]>rq[j+1])
{
temp=rq[j];
rq[j]=rq[j+1];
rq[j+1]=temp;
}
}
}
//Position
for(i=0;i<n;i++)
{
if(rq[i]>h)
{
hPos=i-1;
break;
}
}
//Schedule
sq[0]=h;
printf("\nScheduling\n");
if(h<(dEnd-h))
{
for(i=hPos;i>=0;i--)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
for(i=n-1;i>hPos;i--)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
}
else
{
for(i=hPos+1;i<n;i--)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
for(i=0;i>=hPos;i++)
{
sq[count]=rq[i];
count++;
printf("\t%d
",rq[i]);
}
}
printf("\n Head Movements: ");
for(i=0;i<n;i++)
{
if(sq[i]>sq[i+1])
{
sum+=(sq[i]-sq[i+1]);
}
else
{
sum+=(sq[i+1]-sq[i]);
}
}
printf(" %d \n",sum);
}
Write a program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN d. C-SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will...
Write a java program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5000 cylinders numbered 0 to 4999. The program will generate a random series of 1,000 cylinder requests and service them according to each of nth algorithms listed above. The program will be passed the initial position of the disk head and report the total amount of head movement required by the algorithm.
Use any language
Task two Write a program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN d. C-SCAN e.LOOK f. C-LOOK Your program will service a disk with 500 cylinders numbered 0 to 499. The program will generate a random series of 20 cylinder requests and service them according to each of the algorithms listed above. The proram will be passed the initial position of the disk head (as a parameter on the command line) and...
*** SIMPLE C PROGRAM WILL RATE GOOD**** PLEASE LEAVE COMMENTS THROUGHOUT THE CODE SO I CAN SEE WHAT IS HAPPENING AND LEARN, THANK YOU! Write a program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN d. C-SCAN e. LOOK f. C-LOOK Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 1,000 cylinder requests and service them according to each of the algorithms listed above....
1. Suppose that a disk drive has 5,000 cylinders, numbered 0 to 4,999. The drive is currently serving a request at cylinder 2,150, and the previous request was at cylinder 1,805. The queue of pending requests, in FIFO order, is: 2,069 1,212 2,296 2,800 544 1,618 356 1,523 4,956 3,681 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests for each of the following disk-scheduling...
Suppose that a disk drive has 10,000 cylinders, numbered 0 to 10,000. The drive is currently serving a request at cylinder 7,423 and the previous request was at cylinder 8213. The queue of pending requests, in FIFO order, is: 9324, 6324, 7232, 1304, 5621, 105, 5382, 3241, 2425, 9891. Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests for each of the following disk-scheduling algorithms?...
I/O Scheduling Algorithms a) For each of the following scheduling algorithms, give a 1-2 sentence description of how it works. The description should be precise enough to distinguish each algorithm from the others. Algorithms: FCFS, SSTF, SCAN, C-SCAN, C-LOOK. (1 point) b) Given a hard disk with 200 cylinders and a queue with jobs having the following cylinder requests: 80, 190, 70, 130, 30, draw a diagram of the movements of the head for each of the algorithms listed in...
Suppose that a disk drive has 6,000 cylinders, numbered 0 to 5999. The drive is currently serving a request at cylinder 3150, and the previous request was at cylinder 1805 (Hint: this indicates the reading head’s moving direction). The queue of pending requests, in FIFO order, is: 3511, 2332, 2800, 3192, 658, 1296, 1918, 1356, 5936, 2527 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending...
Suppose a disk system has 200 cylinders, numbered 0 to 199. Assume that the read / write head is at cylinder 63. Determine the order of head movement for each algorithm to satisfy the following stream of requests received in the following order: Queue: 100, 175, 51, 133, 8, 140, 73, 77 Head: 63 -Draw head movement for Shortest Seek Time First (SSTF) algorithm. -Calculate the total head movement for SSTF algorithm -Draw head movement for SCAN algorithm. *The disk...
Suppose that a disk drive has 6,000 cylinders, numbered 0 to 5999. The drive is currently serving a request at cylinder 2150, and the previous request was at cylinder 1105. The queue of pending requests, in FIFO order, is: 2629, 3722, 2805, 3192,773, 1939, 1296, 1918, 5730, 2152, 1356 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests for each of the following disk-scheduling algorithms?...
Suppose that a disk drive has 1000 cylinders, numbered 0 to 999. The drive is currently serving a request at cylinder 200, and the previous request was at cylinder 100. The queue of pending requests, in order, is 61, 270, 913, 774, 948, 422, 750, 509, 13 Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests using the SSTF disk-scheduling algorithm?