Write a C Program to Implement the Disk Scheduling Algorithm for First Come First Served (FCFS)

Aim:

To write a C Program to Implement the Disk Scheduling Algorithm for First Come First Served (FCFS).

Description:

  • Disk Scheduling is the process of deciding which of the cylinder request is in the ready queue is to be accessed next.
  • The access time and the bandwidth can be improved by scheduling the servicing of disk I/O requests in good order.

Access Time:

The access time has two major components: Seek time and Rotational Latency.

Seek Time:

Seek time is the time for disk arm to move the heads to the cylinder containing the desired sector.

Rotational Latency:

Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head.

Bandwidth:

The disk bandwidth is the total number of bytes transferred, divided by the total time between the first request for service and the completion of the last transfer.

Algorithm:

  1. Input the maximum number of cylinders and work queue and its head starting position.
  2. First Come First Serve Scheduling (FCFS) algorithm – The operations are performed in order requested
  3. There is no reordering of work queue.
  4. Every request is serviced, so there is no starvation
  5. The seek time is calculated.
  6. Display the seek time and terminate the program.

Exercise:

  • Consider 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,965, 3681

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?

  1. FCFS
  2. SSTF
  3. SCAN
  4. LOOK
  5. C-SCAN
  6. C-LOOK

Program:

#include<stdio.h>
int request[50];
int SIZE;
int dist(int a,int b)
{
if(a>b)
return a-b;
return b-a;
}
void fcfs(int n)
{
int head,i;
int seekcount=0;
printf("ENTER THE CURRENT HEAD :\n");
scanf("%d",&head);
for(i=0;i<n;i++)
{
if(request[i]<SIZE-1){
seekcount=seekcount+dist(head,request[i]);
head=request[i];
}
}
printf("TOTAL DISTANCE : %d",seekcount);	
}
int main()
{
int n,i;
printf("ENTER THE DISK SIZE :\n");
scanf("%d",&SIZE);
printf("ENTER THE NO OF REQUEST SEQUENCE :\n");
scanf("%d",&n);
printf("ENTER THE REQUEST SEQUENCE :\n");
for(i=0;i<n;i++)
scanf("%d",&request[i]);
fcfs(n);	
}

Execution:

Input:
200 8 176 79 34 60 92 11 41 114 50


Output:

ENTER THE DISK SIZE :
ENTER THE NO OF REQUEST SEQUENCE :
ENTER THE REQUEST SEQUENCE :
ENTER THE CURRENT HEAD :
TOTAL DISTANCE : 510

Result:

Thus Disk Scheduling Algorithm for First Come First Served (FCFS) program was executed Successfully.

Leave a Comment