Spring 1999 Qualifying Exam: Operating Systems Solutions
 

Q1:  It should be possible to implement general semaphores using  binary semaphores. We can use the operations waitB and signalB and  two binary semaphores, delay and mutex. Please consider the following  example:

procedure Wait(var s : semaphore);
begin
    WaitB(mutex);
    s = s -1;
    if s < 0 then
        begin
            SignalB(mutex);
            WaitB(delay);
        end;
    else
        SignalB(mutex);
end;

procedure Signal(var s : semaphore);
begin
    WaitB(mutex);
    s = s + 1;
    if s  <= 0 then
        SignalB(delay);
    SignalB(mutex);
end;

At first, s is set to the desired semaphore value. Each Wait  decrements the semaphore s, and each Signal increments it. The binary  semaphore mutex, which is initially set to 1, assures that we have  mutual exclusion for the operations on s. The binary semaphore delay,  which is initialized to 0, is used to suspend processes.  Looks great - eh? Well, there is s serious flaw in the code provided  above. Your task is to find and explain the flaw and then to suggest  the change in the code that will remedy it. Hint: The number of lines  of code that must be changed is quite small.

Answer:  Move the else statement from its current position in the Wait  procedure to the corresponding position in the Signal procedure.
 

Q2:  We generally agree that the following are valid reasons to use  threads in processes.

a. there is less work involved in creating a new thread in a process  than "forking" another process
b. communications between threads within a process are simpler than  communications between processes

Please describe at least two other reasons that threads are an  attractive alternative to "forking" off new processes.

Answer:

  1. context switching is greatly simplified and therefore much  faster,
  2. sharing of resources is simplified


Q3:  Consider a UNIX file system represented by the following skelital INODE:

        file name
        date created
        date modified
        ,,,
        block 0 pointer (direct)
        block 1 pointer (direct)
        ...
        block 11 pointer (direct)
        singly indirect block pointer
        doubly indirect block pointer
        triply indirect block pointer

Assume also that the disk sector and block sizes are both 8K. If the  disk pointers are 32-bits with 8 bits to identify the physical disk  and 24 bits to identify the physical block, then
 

  1. what is the largest file size supported
  2. assuming that no information other than the file inode is already  in main memory, how many disk accesses are required to access the  byte at location 13,423,956 in the file
  3. what is the max partition size supported


Answer:
 

  1. the max file size supported is greater than 63TB
  2. clearly, the 12 direct pointers cover only 96KB and the first  indirect block covers the next 16MB. the byte we are looking for will  be in the first indirect portion of the file. we will need then two  accesses: on for the first indirect block and one for the block  containing the data
  3. as there are 24 bits for identifying the blocks within a  partition, a partition can only be 2^24 x 8K or 128GB


Q4:  What sorts of file organization would you chhose to get the best  speed of access, use of storage and ease of updating when the data are
 

  1. updated infrequently and accessed frequently in random order
  2. update frequently and accessed relative infrequently
  3. updated frequently and accessed frequently in random order


Answer:

  1. indexed
  2. indexed sequential
  3. hashed


Q5: Most round robin schedulers used fixed size quanta.
 

  1. Give an argument in favor of small quantum.
  2. Give an argument for large quantum
  3. What types of systems and jobs benefit by each of the above
  4. Are ther any for which both would work well


Answer:

  1. Gives faster response times
  2. Will enhance throughput
  3. Time sharing for 1) and batch for 2)
  4. combined time sharing and batch system - these are not common  because they are good at neither.