0% found this document useful (0 votes)
329 views4 pages

FCFS Disk Scheduling Algorithms

The document describes the First Come First Serve (FCFS) disk scheduling algorithm. FCFS processes requests in the order they arrive in the disk queue. It calculates the total number of seek operations by finding the absolute distance between the disk head and each requested track and incrementing a seek count. The algorithm takes a request array and initial head position as input, calculates the distance to each track, updates the head position, and outputs the total seeks and seek sequence.

Uploaded by

Tashu Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
329 views4 pages

FCFS Disk Scheduling Algorithms

The document describes the First Come First Serve (FCFS) disk scheduling algorithm. FCFS processes requests in the order they arrive in the disk queue. It calculates the total number of seek operations by finding the absolute distance between the disk head and each requested track and incrementing a seek count. The algorithm takes a request array and initial head position as input, calculates the distance to each track, updates the head position, and outputs the total seeks and seek sequence.

Uploaded by

Tashu Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PROGRAM NO.

7
FCFS Disk Scheduling Algorithms

Prerequisite: Disk scheduling algorithms.


Given an array of disk track numbers and initial head position, our task is to find the total number
of seek operations done to access all the requested tracks if First Come First Serve (FCFS) disk
scheduling algorithm is used.

First Come First Serve (FCFS)

FCFS is the simplest disk scheduling algorithm. As the name suggests, this algorithm entertains
requests in the order they arrive in the disk queue. The algorithm looks very fair and there is no
starvation (all requests are serviced sequentially) but generally, it does not provide the fastest
service.

Algorithm:
1. Let 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.
2. Let us one by one take the tracks in default order and calculate the absolute distance of
the track from the head.
3. Increment the total seek count with this distance.
4. Currently serviced track position now becomes the new head position.
5. Go to step 2 until all tracks in request array have not been serviced.
Example:

Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50

Therefore, the total seeks count is calculated as:


= (176-50)+(176-79)+(79-34)+(60-34)+(92-60)+(92-11)+(41-11)+(114-41)
= 510
Implementation:
Implementation of FCFS is given below. Note that distance is used to store absolute distance
between head and current track position.

/ C++ program to demonstrate


// FCFS Disk Scheduling algorithm
  
#include <bits/stdc++.h>
using namespace std;
  
int size = 8;
  
void FCFS(int arr[], int head)
{
    int seek_count = 0;
    int distance, cur_track;
  
    for (int i = 0; i < size; i++) {
        cur_track = arr[i];
  
        // calculate absolute distance
        distance = abs(cur_track - head);
  
        // increase the total count
        seek_count += distance;
  
        // accessed track is now new head
        head = cur_track;
    }
  
    cout << "Total number of seek operations = "
         << seek_count << endl;
  
    // Seek sequence would be the same
    // as request array sequence
    cout << "Seek Sequence is" << endl;
  
    for (int i = 0; i < size; i++) {
        cout << arr[i] << endl;
    }
}
  
// Driver code
int main()
{
  
    // request array
    int arr[size] = { 176, 79, 34, 60, 92, 11, 41, 114 };
    int head = 50;
  
    FCFS(arr, head);
  
    return 0;
}

OUTPUT

Input:
Request sequence = {176, 79, 34, 60, 92, 11, 41, 114}
Initial head position = 50

Output:
Total number of seek operations = 510
Seek Sequence is
176
79
34
60
92
11
41
114

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy