CSC 110 Lab 5
Operating Systems

Names: __________________________________________

Overview

In this lab you will study various algorithms that are used by operating systems for resource management.

CPU Scheduling

The operating system is responsible for scheduling use of the computer's CPU. There are many different algorithms that can be used. In this part of the lab, you will run a simple applet that illustrates how some of these algorithms work. Before doing so, give a short description of how each of the following scheduling algorithms decides which process to execute:

  1. First-Come, First-Served







  2. Shortest Job First







  3. Shortest Job First with Preemption







  4. Round Robin







Scheduling Algorithms
Now open the CPU Scheduling applet and see if your descriptions are accurate.

Comparing Algorithms

Have your instructor or TA initial your sheet here: _____________.


Evaluating Scheduling Performance

There are various ways to measure the performance of a scheduling algorithm. Here are a few:

Let's look at FCFS scheduling. Consider the performance of the FCFS algorithm for three processes:
  1. P1 (takes 24 seconds)
  2. P2 (takes 3 seconds)
  3. P3 (takes 3 seconds)
If arrive in order P1, P2, P3, compute the following:
  1. Waiting Time?


  2. Turnaround Time?


  3. Throughput?


What about if processes come in order P2, P3, P1? Compute the following:
  1. Waiting Time?


  2. Turnaround Time?


  3. Throughput?


 
 
  Have your instructor or TA initial your sheet here: _____________.


Deadlock Management

The Dining Philosophers problem is a metaphor for a resource management problem in operating systems. The chopsticks represent shared resources, and the philosophers represent processes that sometimes need the resources.

Use this Dining Philosophers Applet to do the following:

Have your TA or instructor initial your sheet here: _____________.

Challenge Problems:

The Hierarchical Algorithm (with waiting) is a deadlock prevention algorithm that works as follows:

Given a request from process P for resource R, the resource manager follows these rules:

if the resource R does not exist, then
   refuse the request
else
    if process P is holding a resource R' with higher priority than resource R, then
        refuse the request
    else
        let process P wait for the resource (in a queue)
        and when the process reaches the front of the
        queue, grant process P exclusive access to resource R
    end if
end if

Here is a simple example of how this might work:

Question:

In the hierarchical algorithm for preventing deadlock, each resource type is assigned a unique integer as a priority, with 2 as lowest priority and 0 as highest priority. Suppose we have the following:

Given this sequence of requests and frees:

  1. P1 requests R1,
  2. P3 requests R3,
  3. P1 requests R2,
  4. P1 frees R2,
  5. P2 requests R2,
  6. P2 frees R2,
  7. P3 requests R2,
  8. P3 frees R2

Which of the above REQUESTS will be REFUSED by the hierarchical algorithm, and which will be GRANTED?








Have your TA or instructor initial your sheet here: _____________.