CS 110 Homework Assignment 2
Due: Friday, March 8, 2002, at 9 PM
Turn in your assignments in the bin outside Geoff's office.
Late homework will be penalized; see the
late policy for more information.
We also will not accept handwritten material or printouts in which
long lines are wrapped in the middle of a word.
We prefer that you use a text processor. You might try troff
or latex in combination with xfig.
Also remember to date and time stamp your homework.
- 3 points:
MOS #2.22, p. 154.
Consider a computer that does not have a TSL instruction but
does have an instruction to swap the contents of a register and a
memory word in a single indivisible action. Can that be used
to write a route enter_region such as the one found
in Fig. 2-22?
- 3 points:
MOS #2.31, p. 155.
In the solution to the dining philosophers problem
(Fig. 2-20), why is the state variable set to HUNGRY
in the procedure take_forks?
- 3 points:
MOS #2.32, p. 155.
Consider the procedure put_forks in Fig. 2-20.
Suppose that the variable state[i] was set
to THINKING after the two calls to
test, rather than before. How would this
change affect the solution?
- 3 points:
MOS #2.38, p. 156.
Measurements of a certain system have shown that the average
process runs for a time T before blocking on I/O. A
process switch requires a time S, which is
effectively wasted (overhead). For round-robin scheduling
with quantum Q, give a formula for the CPU efficiency
for each of the following:
- Q = infinity
- Q > T
- S < Q < T
- Q = S
- Q nearly 0
Note: The CPU efficiency is defined as the CPU time spent
doing useful work, divided by the total CPU time.
- 3 points:
MOS #2.39, p. 156.
Five jobs are waiting to be run. Their expected run times
are 9, 6, 3, 5, and x. In what order should they be
run to minimize average response time? (Your answer will be
depend on x.)
- 3 points:
MOS #2.44, p. 157.
A soft real-time system has four periodic events with periods
of 50, 100, 200, and 250 msec each. Suppose that the four
events require 35, 20, 10, and x msec of CPU time,
respectively. What is the largest value of x for
which the system is schedulable?
- 5 points:
Consider a variant of the RR (Round Robin) scheduling
algorithm where the entries in the ready queue are pointers to
the PCBs (Process Control Blocks).
- What would be the effect of putting two pointers
to the same process in the ready queue?
- How would you modify the basic RR algorithm to
achieve the same effect without the duplicate
pointers?
- 3 points:
Suppose that a scheduling algorithm favors those processes
that have used the least processor time in the recent
past. Why will this algorithm favor I/O bound programs and yet
not permanently starve CPU-bound programs?
- 2 points:
Log in to Turing. Run ps
and determine:
- The parent process of
ps
, owned by you.
- The grandparent of
ps
.
- The longest chain of parent/child processes for your
login session.
- The scheduling priority of your processes.
Turn in an annotated script file of your ps
answering
the questions above.
- 3 points:
MOS #2.50, p. 157.
Consider a bathroom that can be used by members of either
gender. When a person of one gender is present, other persons
may enter, but persons of the opposite gender must wait until
the bathroom is empty. A sign on the bathroom door indicates
one of three states:
- Empty
- Women present
- Men present
Write pseudocode for the following procedures:
- woman_wants_to_enter
- man_wants_to_enter
- woman_leaves
- man_leaves
You may use whatever counters and synchronization techniques
you like.
- 4 points:
Modify your solution to the previous problem to prevent
starvation.
Last modified March 2, 2002 by geoff@cs.hmc.edu