






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions to the cs162 operating systems midterm exam held at the university of california, berkeley in spring 2001. Topics such as lightweight versus heavyweight processes, processor utilization, turnaround time, and multiprogrammed batch systems. Students are required to answer questions related to these topics and provide approximate values for large n.
Typology: Exams
1 / 10
This page cannot be seen from the preview
Don't miss anything!







University of California, Berkeley College of Engineering Computer Science Division – EECS
Spring 2001 Anthony D. Joseph
March 7, 2001 CS162 Operating Systems
Your Name:
SID AND 162 Login:
TA:
Discussion Section:
General Information: This is a closed book and notes examination. You have ninety 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 1 12
Total 100
Solutions
b. (8 points) List two reasons why lightweight processes are better than heavyweight ones. i) 4 points for each of the following reasons:
ii)
For large N, compute approximate values for these quantities for one, two, and four simultaneous jobs, assuming that the period T is distributed in each of the following ways:
Solutions
iii) 4 jobs, Turnaround time and Processor utilization:
TAT = (2N – 1)T, CPU utilization = 100%. We also accepted 2NT for TAT.
b. (9 points) I/O first and fourth quarters, processor second and third quarters. i) 1 job, Turnaround time and Processor utilization:
2 points for TAT and 1 for utilization. Same answer as part a for 1 job.
ii) 2 jobs, Turnaround time and Processor utilization:
Same answer as above for part a for 2 jobs.
iii) 4 jobs, Turnaround time and Processor utilization:
Same answer as above for part a for 4 jobs.
2 points for correct answer, 2 points for good reason, 1 point for mediocre reason. FIFO is the optimal choice, since in a batch system, the primary concern is with throughput, and the less context switching, the more processing time is available for the process. Policies that minimize context switching are best. We awarded 1 point for swapped incorrect answers for each part, IF there was a reasonable justification that indicated the student understood the tradeoffs involved.
ii) Interactive, time-sharing system:
Round-robin is the optimal choice, since the primary concern is with turnaround time. Time-slicing is preferred because it gives all the processes access to the processor over a short period of time.
Solutions
b. (15 points) Consider the following processes, arrival times, and CPU processing requirements:
Process Name Arrival Time Processing Time 1 0 4 2 1 4 3 4 3 4 8 2
For each of the following scheduling algorithms, fill in the table with the process that is running on the CPU. Assume a 1 unit timeslice for timeslice-based algorithms. For RR, assume that an arriving thread runs at the beginning of its arrival time.
Time FIFO RR SRTF 0 1 1 1
1 1 2 1
Average response time
Solutions
No Credit – Problem X: (000000000000 points)
From a student in CS ###: For a computer programming class, I sat directly across from someone, and our computers were facing away from each other. A few minutes into the class, he got up to leave the room. I reached between our computers and switched the inputs for the keyboards. He came back and started typing and immediately got a distressed look on his face.
He called the Lab TA over and explained that no matter what he typed, nothing would happen. The TA tried everything. By this time I was hiding behind my monitor and quaking red- faced.
I started to type, “Leave me alone!”
They both jumped back, silenced. “What the #$?!#$” the TA said.
I typed, “I said leave me alone!”
The student got real upset. “I didn't do anything to it, I swear!” It was all I could do to keep from laughing out loud. The conversation between them and HAL 2000 went on for an amazing five minutes.
Me: “Don't touch me!”
Student: “I’m sorry, I didn't mean to hit your keys that hard.”
Me: “Who do you think you are anyway?!” Etc. Finally, I couldn’t contain myself any longer and fell out of my chair laughing.
After they had realized what I had done, they both turned beet red.
Funny, I never got more than a C- in that class.
Solutions
a. (6 points) Specify the correctness constraints. Be succinct and explicit in your answer.
_1) Each hydrogen thread waits to be grouped with one other hydrogen and oxygen before returning.
b. (12 points) Observe that there is only one condition any thread will wait for (i.e., a water molecule being formed). However, it will be necessary to signal hydrogen and oxygen threads independently, so we choose to use two condition variable s, waitingH and waitingO. State variable description Variable name Initial value Number of waiting hydrogen threads wH 0 Number of waiting oxygen threads wO 0 Number of active hydrogen threads aH 0 Number of active oxygen threads aO 0
You start with the following code: Hydrogen() { wH++; lock.acquire(); while (aH == 0) { if (wH >= 2 && wO >= 1) { wH-=2; aH+=2; wO-=1; aO+=1; waitingH.broadcast(); waitingO.signal(); } else { lock.release(); waitingH.wait(); lock.acquire(); } } lock.release(); aH--; }
Solutions
Consider the following snapshot of a system with five processes (p1, ... p5) and four resources (r1, ... r4). There are no current outstanding queued unsatisfied requests. currently available resources r1 r2 r3 r 2 1 0 0
current allocation max demand still needs Process r1 r2 r3 r4 r1 r2 r3 r4 r1 r2 r3 r p1 0 0 1 2 0 0 1 2 0 0 0 0 p2 2 0 0 0 2 7 5 0 0 7 5 0 p3 0 0 3 4 6 6 5 6 6 6 2 2 p4 2 3 5 4 4 3 5 6 2 0 0 2 p5 0 3 3 2 0 6 5 2 0 3 2 0
a. (5 points) Compute what each process still might request and fill in the “still needs” columns.
One point for each correct row.
b. (8 points) Is this system currently deadlocked, or will any process become deadlocked? Why or why not? If not, give an execution order.
Four points for correct answer: not deadlocked and will not become deadlocked. Four points for using the Banker’s algorithm, to determine the process finishing order: p1, p4, p5, p2, p3.
c. (10 points) If a request from p3 arrives for (0, 1, 0, 0), can that request be safely granted immediately? In what state (deadlocked, safe, unsafe) would immediately granting the whole request leave the system? Which processes, if any, are or may become deadlocked if this whole request is granted immediately?
Change available to (2, 0, 0, 0) and p3’s row of “still needs” to (6, 5, 2, 2). Now p1, p4, and p5 can finish, but with available now (4, 6, 9, 8) neither p2 nor p3’s “still needs” can be satisfied. So, it is not safe to grant p3’s request. Correct answer NO ( points). State is unsafe (4 points) as the system may or may not deadlock. Processes p2 and p3 may deadlock (4 points, each incorrect one was –2 points).