CS3013 Practice Mid-Term Exam

  1. Operating system structures:

    1. Which operating system structure is typically more robust, a micro-kernel or a simple structure? Briefly explain why.
    2. Briefly explain why a virtual machine operating system often suffers in performance.

  2. Process control block:

    1. The Linux struct task_struct PCB does not store all the complete struct rusage data. What are at least two reasons it does not?
    2. Is a thread control block smaller or larger than a process control block? Why or why not?

  3. Four processes are ready to run. Their CPU burst times are 2, 4, 2 and 6.

    1. In what order are they run under a FIFO scheduling algorithm?
    2. What is the average waiting time?
    3. How close is this to the best average waiting time we could have had for these processes?
    4. What is the throughput for the FIFO algorithm?
    5. If a context switch takes .1 units, how much additional overhead would a Round-Robin (quantum = 1) scheduling algorithm add to the FCFS scheduling algorithm?

  4. Consider the following SOS semaphore implementation of a wait call (additions to system.h shown on top):

    
       /*--------------------------------------*/
       /* extra system.h stuff */
       #define NUM_SEMS 50
    
       /* semaphore data structures */
       struct semaphore {
         int allocated;
         int count;
         int use_count;
         int id;
         pid_queue queue;
       };
    
       struct semaphore sema[NUM_SEMS];
       /*--------------------------------------*/
    
       /** signal **/
       void SignalSemaphore(int sid) {
      
         sema[sid].count++;
         if (sema[sid].count <= 0)
           pid = remove(sema[sid].queue);
           pd[pid].state = READY;
         }
        return;
       }
    
    
    

    Write the corresponding wait code for the below prototype:

       void WaitSemaphore(int sid);
    

  5. For the SignalSemaphore code in previous problem, where might there be a race condition in the OS itself? What solutions might the OS use to avoid any race conditions in SignalSemaphore? Be specific.

  6. Consider running the following psuedo-code on a Unix system:

        /* global variable */
        int n=0
        main() { 
           fork()
           n = n + 1
           printf("%d ", n)
        } 
        

    Assume all system calls succeed.

    1. What are the possible outputs? Consider all combinations.

    2. Assume that n is changed to a variable in shared memory among all processes and the code is re-compiled and ran. Now,what are the possible outputs?

  7. Consider the test_and_set solution for a race condition we discussed in class:

      int lock /* shared */
      while (1) {
        while (test_and_set(lock)) /* no op */ ;
        /* critical region */
        lock = false
        /* remainder */
      }
    
    1. While the above solution does satisfy mutual exclusion, what condition does it not satisfy and why?
    2. What is the major drawback the above code has over the use of semaphores?

  8. Using the SOS process control block (struct ProcessDescriptor) as declared in system.h as a template, provide a struct ThreadDescriptor that contains exactly enough information to save and restore threads and provide a way to reference the containing process.

  9. Provide two programming examples of multithreading that do NOT improve performance over a single thread solution.


Return to the CS3013 Home Page

Send all questions to the TA mailing list.