=========================preview======================
(COMP252)[2009](f)final~2385^_10010.pdf
Back to COMP252 Login to download
======================================================
HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
Fall 2009 COMP 252 Operating System
Final Examination
December 19, 2009
Name: KEY Student ID:
Email: Lab Section Number:
Instructions:
1.
The examination paper (12 pages) consists of 6 questions.

2.
Write your name, student ID, email and lab section number on this page.

3.
Please answer the questions in the spaces provided on the exam paper.

4.
Please read each question very carefully before attempting to answer them.

5.
Please answer each question clearly and to the point. Make sure that your answers are neatly written.

6.
Keep all pages stapled together.

7.
The examination period will last for 2 hours, 8:30 amC10:30 am

8.
Stop writing immediately when the time is up.


Question Percentage % Scores
1 18
2 18
3 20
4 23
5 16
6 5
TOTAL 100

Question 1 Synchronization and Deadlocks (18 points)
I) What is critical section? (2 points)
Answer: piece of code that only one thread can execute at once. (Only one thread at a time will get into this section of code).
Must emphasize it is 'code' section, otherwise will be deduct 1 point
II) What is a condition variable in a monitor used for? What occurs if wait() is called on a condition variable in a monitor? (2 points)
Answer: (1 point each) Condition variable specifies a queue of processes or threads waiting for certain event inside a critical section. Wait() suspends a process or a thread inside the monitor (inside the critical section).
III) What are the four conditions that must hold simultaneously when there is a deadlock? Are they also sufficient conditions for a deadlock to occur? (3 points)
Answer: Mutual exclusion, hold and wait, no preemption, and circular wait. (0.5 pt each) No, they are only the necessary conditions. (1 point)
IV) Consider the following snapshot of a system with 6 processes and 5 resource types. Please answer the following questions using the Bankers algorithm. (11 points)
Allocation Max Available
A B C D E A B C D E A B C D E
P0 0 0 1 2 3 0 0 3 2 3 2 1 2 0 0
P1 2 0 0 0 1 2 7 5 0 2
P2 0 0 3 4 2 6 6 5 6 4
P3 2 3 5 4 0 4 3 5 6 3
P4 0 3 3 2 0 0 6 5 2 0
P5 3 2 4 0 0 4 2 5 2 6

IV.1) What is the content of the Need matrix, which denotes the number of additional resources possibly needed by each process? (2 points)
Answer: Need = Max C Allocation IV.2) What is a safe state? Please show that the system above is in a safe state. Please illustrate the resources available after each intermediate step. (5 points)
Need
A B C D E
P0 0 0 2 0 0
P1 0 7 5 0 1
P2 6 6 2 2 2
P3 2 0 0 2 3
P4 0 3 2 0 0
P5 1 0 1 2 6

Answer: there exists a safe sequence that all process can acquire the needed resources
and complete execution. (1 point)
<P0, P3, P4, P1, P2, P5>