







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








University of California, Berkeley College of Engineering Computer Science Division – EECS
Spring 2004 Anthony D. Joseph
March 18, 2004 CS162 Operating Systems
Your Name:
SID AND 162 Login:
TA:
Discussion Section:
General Information: This is a closed book and notes examination. You have 120 minutes to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points given to the question; there are 100 points in all. You should read all of the questions before starting the exam, as some of the questions are substantially more time consuming.
Write all of your answers directly on this paper. Make your answers as concise as possible. If there is something in a question that you believe is open to interpretation, then please ask us about it!
Problem Possible Score
Solutions
TRUE FALSE Why? FALSE. Threading allows I/O to be overlapped with computation which can provide substantial performance improvements. 4 points for each. 2 points for partial answers.
ii) (4 points) Protection and isolation between applications and between applications and the operating system can be provided without hardware support.
TRUE FALSE Why? TRUE. Using strong typing or software fault isolation can provide the same protection and isolation capabilities as hardware.
iii) (4 points) After a UNIX fork operation, the parent and new child process are identical in all respects.
TRUE FALSE Why? FALSE. One register is different between the parent and child, and is used to determine which process is the parent and which is the child..
b. (5 points) Consider a system with a mixture of I/O bound processes and CPU bound processes i) (3 points) Explain how this mixture of processes maximizes system utilization: We want to keep all parts of the system busy by overlapping I/O operations with CPU operations. Overall, if we have some processes using the CPU while others are waiting on I/O, then the system will be more utilized.
Solutions
c. (6 points) Suppose that a scheduling algorithm (at the level of short-term CPU scheduling) favors those processes that have used the least processor time in the recent past. Why will this algorithm favor I/O-bound processes and yet not permanently starve CPU-bound processes? We awarded three points for saying that I/O bound processes generally sit idle for relatively long periods of time. When they finally get their I/O, they will not have run for a long time and will therefore be favored in scheduling relative to processes which have just been running. We awarded an additional three points for saying that if CPU-bound processes get blocked long enough by I/O-bound processes, they too will eventually not have run for a long time and they will be scheduled. Also, if there aren't too many I/O-bound processes, the CPU-bound ones will get to run when the I/O-bound ones are blocked.
We subtracted two points for not explicitly stating that I/O uses less CPU, subtracted two points for saying that the CPU-bound processes won’t run until the end, and subtracted two points for saying that round robin scheduling was the reason. We deducted three points for saying that you have to wait until all I/O-bound processes finish, subtracted three points for saying that the CPU-bound processes run because of interrupts, subtracted three points for saying that at first CPU- bound process get to run.
We took off two points for saying that the minimum priority process gets CPU time.
Solutions
No Credit – Problem X (000000000000 points)
The following is an excerpt from The Washington Post's Style Invitational invitation to readers to: take any word from the dictionary, alter it by adding, subtracting, or changing one letter, and supply a new definition.
Here are this year's winners:
And the pick of the literature:
Solutions
public class Semaphore {
Semaphores can be implemented with a monitor and a condition variable. The monitor protects access to the semaphore's value, and the condition variable lets you block/wakeup threads. Note too the < 0 in Semaphore.P() and =0 in Semaphore.V(). You can argue that the conditional in Semaphore.V() is unnecessary, for if the value is greater than zero, there will be no threads waiting on the conditional variable. public class Semaphore { private Monitor mon = null; private ConditionVariable cv = null; int value;
public Semaphore(int initialValue) throws InvalidInitValue{ /* Create and return a semaphore with initial value: initialValue/ if (initialValue < 0) throw InvalidInitValue; mon = new Monitor(); cv = new ConditionVariable(); value = initialValue; } public P() { / Call P() on the semaphore / mon.Enter(); value--; if (value < 0) cv.Wait(); / OR “while (value <= 0) cv.Wait(); value--;” / mon.Exit(); } public V() { / Call V() on the semaphore / mon.Enter(); value++; cv.Notify(); / You could optionally include “if (value <= 0)” */ mon.exit(); } }
Solutions
Solutions
P2 3 5
P3 1 1
P4 1 2
P5 3 3
ii. (6 points) At least how many plates would the restaurant need to add? If add 1 plate, there are 9 plates and 12 bowls totally. Initially, A = (1, 1). Serve P3, A = (1, 2). Serve P4, A = (2, 4). So there are not enough resources for serving the 5 parties.
If add 2 plates, there are 10 plates and 12 bowls totally. Initially, A = (2, 1). Serve P3, A = (2, 2). Serve P4, A = (3, 4). Serve P5, A = (5, 4). Serve P1, A = (7, 7). Serve P2, A = (10, 12).
Therefore, at least 2 plates are needed.
We treated parts (ii) and (iii) as a combined 9 points. If you had an incorrect number of plates, but the correct ordering, we deducted 5 points. If you had an incorrect number of bowls, but the correct number of plates, and an incorrect ordering, we deducted 4 points. If your had the correct number of plates, but an incorrect ordering, we deducted 6 points.
iii. (3 points) Show a safe serving seque nce. A safe serving sequence is P3-P4-P5-P1-P2.
Solutions
The inverted page table is a mapping of physical addresses to virtual addresses. Memory is 4 megabytes, partitioned into 512 pages. Therefore the inverted page table will consist of 512 entries. Each of these entries must have: 19 bits for the virtual page number of the physical page. Some number of bits (16 in Unix) for the processs ID of the process that owns the page. Protection bits (r/w/x)
We awarded two points each for: the correct number of IPT entries, storing the virtual page number in the IPT, storing the process ID in the IPT, and storing the protection bits(any reasonable set was accepted) in the IPT. We subtracted one point for each extraneous item that you stored in the IPT, and subtracted one point for storing the physical page number instead of the virtual page number in the IPT.
b. (5 points) Describe how an IPT is used to translate a virtual address into a physical address. A virtual address is translated to a physical address hashing virtual addresses (worth two points). Thus, in the normal case, the translation may be found in a few memory lookups rather than an entire table traversal. If it is found, and the owning process is equal to the current running process (owning PID check is worth 2 points), then its index in the table is the frame number of the physical page. If it is not found, then a memory fault must occur (not found fault is worth 1 point). We also accepted a general search of the IPT, as described in the book and midterm review session.
Solutions
This page intentionally left blank as scratch space.
Do not write answers on this page
Do not write answers on this page