Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Disk Scheduling Algorithms in Operating Systems: A Practical Lab Project - Prof. Olmsted, Exercises of Computer Science

CS 245 Lab Documentation with textbook links

Typology: Exercises

2021/2022

Uploaded on 02/06/2023

aspeno
aspeno 🇺🇸

4 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Disk Scheduling Lab - Python
This lab project addresses the implementation of IO-scheduling algorithms in an operating
system.
Reference Textbook:Garrido, José M., and Richard Schlesinger. Principles of modern operating
systems. Jones & Bartlett Learning, (any edition 2 - 4)
Each IO request in an operating system is managed by using a data structure called the
Request Control Block (RCB). An RCB contains the request ID, arrival timestamp, cylinder,
address, and the ID of the process that posted the request. The RCB struct is defined as
follows:
RCB = {
request_id:0,
arrival_timestamp=0,
cylinder=0,
address=0,;
process_id=0
}
The set of IO requests in the operating system that are to be processed are tracked in an IO
Request Queue. This data structure is an array of RCBs of the requests.
The NULLRCB is defined as [RID:0, AT:0, CYL:0, ADDR:0, PID:0]
To determine the schedule of servicing the IO requests in an operating system, we consider
three policies:
1. First-Come-First-Served Scheduling (FCFS)
2. Shortest-Seek-Time-First Scheduling (SSTF)
3. LOOK Scheduling (LOOK)
In order to implement the above policies, we need to develop methods that handle the arrival of
IO requests and the completion of IO requests. That is, when a new IO request arrives, we need
to figure out whether to service it immediately or to store it in the IO Request Queue. Whenever
an IO request is completed, we need to figure out the next request from the IO Request Queue
that needs to be serviced. The details of these methods are described below in the specification
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Disk Scheduling Algorithms in Operating Systems: A Practical Lab Project - Prof. Olmsted and more Exercises Computer Science in PDF only on Docsity!

Disk Scheduling Lab - Python

This lab project addresses the implementation of IO-scheduling algorithms in an operating system. Reference Textbook : Garrido, José M., and Richard Schlesinger. Principles of modern operating systems. Jones & Bartlett Learning, (any edition 2 - 4) Each IO request in an operating system is managed by using a data structure called the Request Control Block (RCB). An RCB contains the request ID, arrival timestamp, cylinder, address, and the ID of the process that posted the request. The RCB struct is defined as follows: RCB = { request_id:0, arrival_timestamp=0, cylinder=0, address=0,; process_id= } The set of IO requests in the operating system that are to be processed are tracked in an IO Request Queue. This data structure is an array of RCBs of the requests. The NULLRCB is defined as [RID:0, AT:0, CYL:0, ADDR:0, PID:0] To determine the schedule of servicing the IO requests in an operating system, we consider three policies:

  1. First-Come-First-Served Scheduling (FCFS)
  2. Shortest-Seek-Time-First Scheduling (SSTF)
  3. LOOK Scheduling (LOOK) In order to implement the above policies, we need to develop methods that handle the arrival of IO requests and the completion of IO requests. That is, when a new IO request arrives, we need to figure out whether to service it immediately or to store it in the IO Request Queue. Whenever an IO request is completed, we need to figure out the next request from the IO Request Queue that needs to be serviced. The details of these methods are described below in the specification

and you need to develop code for these methods that follow the specification and place the code in a file named disk.py. A starting place for the file would be: def handle_request_arrival_fcfs(request_queue, current_request, new_request, timestamp): pass def handle_request_completion_fcfs(request_queue): pass def handle_request_arrival_sstf(request_queue, current_request, new_request, timestamp): pass def handle_request_completion_sstf(request_queue, current_cylinder): pass def handle_request_arrival_look(request_queue, current_request, new_request, timestamp): pass def handle_request_completion_look(request_queue, current_cylinder, direction): pass

handle_request_arrival_fcfs

This method implements the logic to handle the arrival of a new IO request in a First-Come-First-Served Scheduler. Specifically, it takes four inputs:

  1. the request queue (an array of RCB structs)
  2. the RCB of the currently-serviced request
  3. the RCB of the newly-arriving request
  4. the current timestamp. The method returns the RCB of the newly-arriving request if the disk is free (indicated by the second parameter being a NULLRCB), otherwise, it returns the RCB of the currently-serviced request after adding the newly-arriving request to the request queue. The signature of the method is as follows: handle_request_arrival_fcfs(request_queue, current_request, new_request, timestamp)

input/output parameter value input request_queue [RID:1, AT:10, CYL:124323, ADDR:124323, PID:1] input queue_cnt 1 output request_queue EMPTY output queue_cnt 0 output RCB [RID:1, AT:10, CYL:124323, ADDR:124323, PID:1] Please refer to Section 5.4.3 of the Modern Operating Systems book for a detailed discussion of the First-Come-First-Served algorithm.

handle_request_arrival_sstf

This method implements the logic to handle the arrival of a new IO request in a Shortest-Seek-First (also known as Shortest-Seek-Time-First) Scheduler. Specifically, it takes four inputs:

  1. the request queue (an array of RCB structs)
  2. the RCB of the currently-serviced request
  3. the RCB of the newly-arriving request
  4. the current timestamp. The method returns the RCB of the newly-arriving request if the disk is free (indicated by the second parameter being NULLRCB), otherwise, it returns the RCB of the currently-serviced request after adding the newly-arriving request to the request queue. The signature of the method is as follows: handle_request_arrival_sstf(request_queue, current_request, new_request, timestamp) A sample execution input and output: input/output parameter value input request_queue EMPTY input queue_cnt 0 input current_request [RID:51, AT:1, CYL:53, ADDR:53, PID:51] input new_request [RID:52, AT:2, CYL:54, ADDR:54, PID:52] input timestamp 2 output request_queue [RID:52, AT:2, CYL:54, ADDR:54, PID:52] output queue_cnt 1 output RCB [RID:51, AT:1, CYL:53, ADDR:53, PID:51] Please refer to Section 5.4.3 of the Modern Operating Systems book for a detailed discussion of the Shortest-Seek-First algorithm.

the Shortest-Seek-First algorithm.

handle_request_arrival_look

This method implements the logic to handle the arrival of a new IO request in a LOOK (also known as Elevator) Scheduler. Specifically, it takes four inputs:

  1. the request queue (an array of RCB structs)
  2. the RCB of the currently-serviced request
  3. the RCB of the newly-arriving request
  4. the current timestamp. The method returns the RCB of the newly-arriving request if the disk is free (indicated by the second parameter being NULLRCB), otherwise, it returns the RCB of the currently-serviced request after adding the newly-arriving request to the request queue. The signature of the method is as follows: handle_request_arrival_look(request_queue, current_request, new_request, timestamp) A sample execution input and output: input/output parameter value input request_queue EMPTY input queue_cnt 0 input current_request [RID:51, AT:1, CYL:53, ADDR:53, PID:51] input new_request [RID:52, AT:2, CYL:54, ADDR:54, PID:52] input timestamp 2 output request_queue [RID:52, AT:2, CYL:54, ADDR:54, PID:52] output queue_cnt 1 output RCB [RID:51, AT:1, CYL:53, ADDR:53, PID:51] Please refer to Section 5.4.3 of the Modern Operating Systems book for a detailed discussion of

the LOOK algorithm.

handle_request_completion_look

This method implements the logic to handle the completion of servicing an IO request in a LOOK Scheduler. Specifically, it takes three input parameters:

  1. the request queue (an array of RCB structs),
  2. the current cylinder
  3. the scan direction. The method determines the request to service next and returns its RCB. If the request queue is empty, the method returns NULLRCB, indicating that there is no request to service next. Otherwise, it picks the next request to service from the request queue. If there are requests in the queue with the same cylinder as the current cylinder, the method picks the one among these requests with the earliest arrival time. Otherwise, if the scan direction is 1 and there are requests with cylinders larger than the current cylinder, the method picks the one among those whose cylinder is closest to the current cylinder. Otherwise, if the scan direction is 1 and there are no requests with cylinders larger than the current cylinder, the method picks the request whose cylinder is closest to the current cylinder. Otherwise, if the scan direction is 0 and there are requests with cylinders smaller than the current cylinder, the method picks the one among those whose cylinder is closest to the current cylinder. Otherwise, if the scan direction is 0 and there are requests with cylinders larger than the current cylinder, the method picks the request whose cylinder is closest to the current cylinder. After picking the RCB from the request queue, as described above, the method removes the RCB from the queue and returns it. The signature of the method is as follows: handle_request_completion_look(request_queue, current_cylinder, scan_direction) A sample execution input and output: input/output parameter value input request_queue [RID:1, AT:52, CYL:58, ADDR:58, PID:1], [RID:2, AT:51, CYL:58, ADDR:58, PID:2], [RID:3, AT:53, CYL:58, ADDR:58, PID:3] input queue_cnt 3