Labels

C program for FCFS disk scheduling algorithm

Introduction to FCFS disk scheduling :

                    The simplest form of disk scheduling is, of course, the first-come, first-served (FCFS) algorithm. This algorithm is intrinsically fair, but it generally does not provide the fastest service. Consider, for example, a disk queue with requests for I/O to blocks on cylinders 98, 183, 37, 122, 14, 124, 65, 67. If the disk head is initially at cylinder 53, it will first move from 53 to 98, then to 183, 37, 122, 14, 124, 65, and finally to 67, for a total head movement of 640 cylinders.

C program for FCFS disk scheduling :




#include<stdio.h>
int main()
{
            int queue[20],n,head,i,j,k,seek=0,max,diff;
            float avg;
            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                                                                                       %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 :




6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. where did u use the max variable?

    ReplyDelete
    Replies
    1. max no of cylinders in disk

      Delete
    2. what is the use of the abs shows declaration function please give me a solution

      Delete
  3. abs means modulus...makes a negative number positive

    ReplyDelete
  4. Nice Web site for Educaion https://www.wisdommaterials.com

    ReplyDelete