University of California, Berkeley
College of Engineering
Computer Science Division EECS
Spring 2024 John Kubiatowicz
Midterm II
SOLUTION
March 14th, 2024
CS162: Operating Systems and Systems Programming
Your Name:
Your SID:
TA Name:
Discussion Section
Time:
General Information:
This is a closed book exam. You are allowed 2 pages of notes (both sides). You have 2 hours to
complete as much of the exam as possible. Make sure to read all of the questions first, 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. On programming questions, we will be looking for
performance as well as correctness, so think through your answers carefully. If there is something
about the questions that you believe is open to interpretation, please ask us about it!
Problem Possible Score
1 18
2 16
3 14
4 13
5 19
6 20
Total 100
Page 1/22
,CS 162 Spring 2024 Midterm II SOLUTION March 14th, 2024
[ Happy Day! ]
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
Page 2/22
, CS 162 Spring 2024 Midterm II SOLUTION March 14th, 2024
Problem 1: True/False [18 pts]
Please EXPLAIN your answer in TWO SENTENCES OR LESS (Answers longer than this may not
get credit!). Also, answers without an explanation GET NO CREDIT.
Problem 1a[2pts]: With the Round Robin scheduling policy, the larger the time quantum, Q, the
higher the throughput of execution.
True ⬜ False
Explain: With a larger time quantum, threads are interrupted less frequently. Consequently, there is
less overhead (saving and restoring of registers, pipeline interruption/draining) and processor mechanisms for
single-threaded performance have more chance to work (caching, branch prediction, etc.)
Problem 1b[2pts]: If the Banker's algorithm finds that it's safe to allocate a resource to an existing
thread, then all threads will eventually complete.
⬜ True False
Explain: Banker’s algorithm only prevents deadlocks caused by resource-related
dependency cycles. Threads could still fail to complete for a variety of other reasons (such as entering
an infinite loop).
Problem 1c[2pts]: Suppose that a shell program wants to execute another program and wait on its
result. It does this by creating a thread, calling exec() from within that thread, then waiting in the
original thread.
⬜ True False
Explain: If the shell only creates a new thread, then calling exec() within that thread will
completely replace the shell with the new program (and hence there won’t be an original thread to do
any waiting). The shell program needs to use fork() to create a new process in which to call exec(),
not a new thread.
Problem 1d[2pts]: Because the CFS scheduler uses the same mechanism to choose the next running
thread regardless of whether a thread is interactive or computational, it has poor interactive behavior.
⬜ True False
Explain: Interactive threads have short bursts and spend most time sleeping; consequently
they will not accumulate as much virtual time as computational threads and will thus run preferentially
when the are ready to run (e.g. when a user has just pressed a key on their keyboard).
Problem 1e[2pts]: A 2-way set-associative cache has a faster hit time than a direct-mapped cache.
⬜ True False
Explain: Unlike a direct-mapped cache, the 2-way set-associative cache must (1) compare
tags after the cache-bank lookup using the index, (2) use the result to select the direction of a mux and
(3) wait for the data to route through the mux. All of these combine to make a 2-way set-associative
cache slower than a direct-mapped cache.
Page 3/22
College of Engineering
Computer Science Division EECS
Spring 2024 John Kubiatowicz
Midterm II
SOLUTION
March 14th, 2024
CS162: Operating Systems and Systems Programming
Your Name:
Your SID:
TA Name:
Discussion Section
Time:
General Information:
This is a closed book exam. You are allowed 2 pages of notes (both sides). You have 2 hours to
complete as much of the exam as possible. Make sure to read all of the questions first, 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. On programming questions, we will be looking for
performance as well as correctness, so think through your answers carefully. If there is something
about the questions that you believe is open to interpretation, please ask us about it!
Problem Possible Score
1 18
2 16
3 14
4 13
5 19
6 20
Total 100
Page 1/22
,CS 162 Spring 2024 Midterm II SOLUTION March 14th, 2024
[ Happy Day! ]
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
Page 2/22
, CS 162 Spring 2024 Midterm II SOLUTION March 14th, 2024
Problem 1: True/False [18 pts]
Please EXPLAIN your answer in TWO SENTENCES OR LESS (Answers longer than this may not
get credit!). Also, answers without an explanation GET NO CREDIT.
Problem 1a[2pts]: With the Round Robin scheduling policy, the larger the time quantum, Q, the
higher the throughput of execution.
True ⬜ False
Explain: With a larger time quantum, threads are interrupted less frequently. Consequently, there is
less overhead (saving and restoring of registers, pipeline interruption/draining) and processor mechanisms for
single-threaded performance have more chance to work (caching, branch prediction, etc.)
Problem 1b[2pts]: If the Banker's algorithm finds that it's safe to allocate a resource to an existing
thread, then all threads will eventually complete.
⬜ True False
Explain: Banker’s algorithm only prevents deadlocks caused by resource-related
dependency cycles. Threads could still fail to complete for a variety of other reasons (such as entering
an infinite loop).
Problem 1c[2pts]: Suppose that a shell program wants to execute another program and wait on its
result. It does this by creating a thread, calling exec() from within that thread, then waiting in the
original thread.
⬜ True False
Explain: If the shell only creates a new thread, then calling exec() within that thread will
completely replace the shell with the new program (and hence there won’t be an original thread to do
any waiting). The shell program needs to use fork() to create a new process in which to call exec(),
not a new thread.
Problem 1d[2pts]: Because the CFS scheduler uses the same mechanism to choose the next running
thread regardless of whether a thread is interactive or computational, it has poor interactive behavior.
⬜ True False
Explain: Interactive threads have short bursts and spend most time sleeping; consequently
they will not accumulate as much virtual time as computational threads and will thus run preferentially
when the are ready to run (e.g. when a user has just pressed a key on their keyboard).
Problem 1e[2pts]: A 2-way set-associative cache has a faster hit time than a direct-mapped cache.
⬜ True False
Explain: Unlike a direct-mapped cache, the 2-way set-associative cache must (1) compare
tags after the cache-bank lookup using the index, (2) use the result to select the direction of a mux and
(3) wait for the data to route through the mux. All of these combine to make a 2-way set-associative
cache slower than a direct-mapped cache.
Page 3/22