Spring 2006 OS Exam: Bugs in Semaphore & Virtual Memory Analysis, Exams of Operating Systems

Solutions and explanations for questions from an operating systems comprehensive exam held in spring 2006. The questions cover topics such as semaphore implementation, virtual memory translation, and distributed services. Answers to the bugs in the semaphore implementation and a detailed explanation of virtual memory translation on modern architectures using tlb and monolithic operating systems. Additionally, it discusses the handling of page faults in l4 and xen systems.

Typology: Exams

2012/2013

Uploaded on 04/07/2013

seshan_kim55
seshan_kim55 🇮🇳

4.7

(3)

54 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
OPERATING SYSTEMS COMPREHENSIVE EXAM, SPRING 2006
This exam contains four questions of equal value. For each question, record your answer
in a separate exam booklet. Answer all questions to the best of your ability.
1. Synchronization
Consider the following implementation of the semaphore wait and signal functions:
1. wait (s)
2. sem s;
3. {
4. if (value (s) == 0) { /* is value of s zero? */
5. putq (s, thisproc ()); /* put this proc on wait queue */
6. block (thisproc ()); /* this proc blocks and yields */
7. }
8. decr (s); /* decrement value of s */
9. }
10.
11. signal (s)
12. sem s;
13. {
14. incr (s); /* increment value of s */
15. if (! emptyq (s)) { /* if wait queue is not empty */
16. unblock (getq (s)); /* get a process and unblock it */
17. }
18. }
incr (s) increments value of semaphore s
decr (s) decrements value of semaphore s
value (s) returns value of semaphore s
putq (s, p) puts process p on semaphore s's queue of waiting processes
getq (s) removes a process from semaphores s's queue and returns it
emptyq (s) returns true if semaphore s's waiting process queue is empty
thisproc () returns the currently running process
block (p) puts process p in blocked state and yields to another process
unblock (p) puts process p in ready state
When either of these functions are called, you may assume that the process running them
will not be preempted. However, the process may voluntarily give up the CPU, as in the
wait function.
(i) There is a bug in the implementation; what is the bug? Identify using the line numbers
where are problem is, and describe how the problem may occur.
(ii) How would you fix the problem? Describe the minimal number of changes, using the
line numbers as references. (You will only get credit if you determine the absolute
minimal number of changes and what they are.)
pf3

Partial preview of the text

Download Spring 2006 OS Exam: Bugs in Semaphore & Virtual Memory Analysis and more Exams Operating Systems in PDF only on Docsity!

OPERATING SYSTEMS COMPREHENSIVE EXAM, SPRING 2006

This exam contains four questions of equal value. For each question, record your answer

in a separate exam booklet. Answer all questions to the best of your ability.

1. Synchronization

Consider the following implementation of the semaphore wait and signal functions:

  1. wait (s)
  2. sem s;
  3. {
  4. if (value (s) == 0) { /* is value of s zero? */
  5. putq (s, thisproc ()); /* put this proc on wait queue */
  6. block (thisproc ()); /* this proc blocks and yields */
  7. }
  8. decr (s); /* decrement value of s */
  9. }
  10. signal (s)
  11. sem s;
  12. {
  13. incr (s); /* increment value of s */
  14. if (! emptyq (s)) { /* if wait queue is not empty */
  15. unblock (getq (s)); /* get a process and unblock it */
  16. }
  17. }

incr (s) increments value of semaphore s

decr (s) decrements value of semaphore s

value (s) returns value of semaphore s

putq (s, p) puts process p on semaphore s's queue of waiting processes

getq (s) removes a process from semaphores s's queue and returns it

emptyq (s) returns true if semaphore s's waiting process queue is empty

thisproc () returns the currently running process

block (p) puts process p in blocked state and yields to another process

unblock (p) puts process p in ready state

When either of these functions are called, you may assume that the process running them

will not be preempted. However, the process may voluntarily give up the CPU, as in the

wait function.

(i) There is a bug in the implementation; what is the bug? Identify using the line numbers

where are problem is, and describe how the problem may occur.

(ii) How would you fix the problem? Describe the minimal number of changes, using the

line numbers as references. (You will only get credit if you determine the absolute

minimal number of changes and what they are.)

2. Virtual Memory

(i) Sketch how virtual address translation works on a modern architecture using a

hardware-managed translation lookaside buffer (TLB) and a monolithic operating system

(e.g., Linux or Windows). Imagine that we are running Emacs as an application on the

system. Start with the step where Emacs executes an instruction that makes a memory

reference to a page that has been paged out to disk, and end with the step where the

Emacs instruction finishes execution. It is sufficient to simply list the steps, a detailed

discussion is not necessary.

(ii) A number of different operating system structures have been proposed over time,

including how virtual memory is managed. Again consider the case where Emacs is

running as an application on a system and causes a page fault. Select two (and only two)

of the following recent systems:

• L

• Xen

• Exokernel

For the two systems you selected, sketch how they handle a page fault by answering the

following questions:

(a) What part of the system (whose address space) receives the initial page fault

exception?

(b) What part of the system (whose address space) stores and manages application page

tables?

(c) What mechanism does the system use to vector a page fault from (a) to (b)?