OPERATING SYSTEMS (CS 377)

Homework 3

Due:  March 28, 2003, 19:30

What to Hand In

Everyone must hand in their own work. Place in your Hand-In directory (~/cs377/hw3/) an ASCII file (i.e., raw text) called "hw3.txt" or a postscript file called "hw3.ps" that contains your name, user id, and answers to the questions listed below. If you use a non-ASCII editor (e.g., MSword), please make sure that you save your final file in ASCII or postscript format (we will not be able to grade your assignment if it is not one of these formats). In MSword, there is a 'save text' option in the save dialog box. You can check the ascii format on the linux side by using the shell commands 'cat', 'more', or 'less'. Answers need not be more than a few sentences (please keep you answers to the point).

The Questions

Short-Answer Questions

1. (6 points) In terms of scalability , discuss the following network topologies: fully connected, partially connected, tree, star, ring, and multi-access bus network.

2. (5 points) What are the major differences between RPC and RMI?

3. (5 points) What are the key properties of DNS? List at least 3.

4. (4 points) What are two major differences between a WAN and a LAN?

long-Answer Questions

These questions require some thought and longer answers than above.

4. (20 points) A barbershop consists of a waiting room with n chairs, and a barber room with one barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs in the waiting room  are occupied, then the customer leaves the shop. If the barber is busy, but chairs in the waiting room are available, then he/she sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber.

(1) (10 points) Suppose we have defined three semaphores, and an int emptyChairs to indicate how many chairs in the waiting room are available:

Semaphore mutex(1);   // for mutual exclusion
Semaphore  barberChair(1);  // for the number of available  access to the barber's chair, 0 or 1
Semaphore  waitingCustomer(0);  // number of customers waiting for service

 int emptyChairs = N;   //number of available chairs in the waiting room

Write a program (pseudo code) to coordinate the barber and the customers, using following classes.

class customer() {
    customer(){
    //need to fill in the customer's behavior
    Get_hair_cut ();
    }
}

class barber() {
    barber(){
        while(TRUE){
        // need to fill in the barber's behavior
        Cut_hair ();
        }
    }
}

(2) (10 points) Use a monitor to solve the Barber's problem.

5. (20 points) The following pseudo code is a version of a Reader-Writer solution. What may happen if we run this Reader-Writer solution (assume multiple instances of both Writers and Readers)? Explain your answer.  How about if we  put  mutex.V() before the  read_data_base() and mutex.P() after the  read_data_base()  in the Reader process?

     Shared{
       Semaphore mutex(1), db(1);
       int readcount = 0;                   //number of processes reading or wanting to
    }

     Writer
    {
         while(TRUE){
              db.P()
              write_data_base();
              db.V();
              sleep_for_some_random_time();
            }
      }

     Reader
    {
        while(TRUE){
           mutex.P();
           readcount = readcount + 1;
           if (readcount==1)
                  db.P();
           read_data_base();
           readcount = readcount - 1;
           if (readcount==0)
                   db.V();
            mutex.V();
            sleep_for_some_random_time();
        }
    }
 

6. How much time did you spend on this assignment?