CS 1550 Practice Mid-Term Exam Questions
These are practice questions similar in form to
those
that may appear on
the mid-term. They are intended to help you prepare to
answer questions of varying formats, not as a comprehensive review of
the
material. REMINDER: Keeping up with the readings has been strongly
emphasized in class.
If you are unsure of the meaning of a question,
feel
free to ask the instructor for clarification (this is acceptable during
the
exam too). On a similar note, it is often useful to explicitly state
any
assumptions you make.
OS History and Introduction
Q: Name the OS architecture that most closely matches the following
statements.
The most common OS architecture (e.g. Linux,and Windows).
Answer: Monolithic
This architecture is what you get if you focus
only
on resource
management, leaving
abstraction
as a later step.
Answer: VM
QNX, VxWorks, and
Mach are
all ______ architecture OSs.
Answer: Microkernel
Q: What is the single most important
criteria
an interactive system's scheduler tries to minimize?
Answer: Average response time.
Scheduling
Q: “Shortest Job First is optimal.”
Explain
this statement, and explain why SJF is therefore not used instead of
“sub-optimal” scheduling policies.
Answer: The trick here is to
consider
“optimal at doing what?” It is optimal at increasing completion rate,
but
what about average turnaround time if starvation occurs? fairness?
response
time?
Q: For the following list of jobs, (job id, admission
time, required CPU time),assume round-robin scheduling with a quantum of
4
time units. Assume an overhead of 1 time unit per context switch –
between
different processes. Assume new jobs are admitted at the tail of the
queue,
and jobs admitted at the same time are queued in the order listed below.
a)
Order of execution.
b)
The average and
individual
turnaround times.
c)
Average time spent waiting for the CPU.
d)
Recalculate a) through c) for a quantum of
8
time units.
Jobs:
(A, 0,
16),
(B, 0, 12), (C, 2, 24), (D, 3, 8), (E, 4, 4), (F, 6, 12)
IPC and Deadlocks
Q: Name the four conditions for deadlock. Are these conditions
necessary
and/or sufficient?
Q: Implement a binary semaphore using an atomic exchange
instruction (XCHG). Give the code for both
P(s) and V(s).
Q: Fix the following code sample
/** Producer
Consumer
Using Semaphores **/
semaphore mutex = 1;
semaphore empty = N;
semaphore full = 0;
int buffer[N];
void producer() {
int item;
while(TRUE) {
item = produce_item();
down(mutex);
down(empty);
insert_item(item,buffer);
up(full);
up(mutex);
}
}
void consumer() {
int item;
while(TRUE) {
down(mutex);
down(full);
item = remove_item(buffer);
up(empty);
up(mutex);
}
}
/** Producer
Consumer
Using Semaphores **/
Answer: Hint – consider the order
of
mutex and counting semaphores. A deadlock
can
easily happen here. Limit the mutex-protected
region to the bare minimum that needs to be protected (around insert_item() and remove_item() to
be
precise).
Q: In a physical computer system, what
can
you do in terms of hardware settings to prevent code from being
interrupted?
Answer: Disabling interrupts.
Q: What is a race condition? Explain by providing a scenario where
one
can occur (e.g. when updating shared variables).
Q: A system provides a “print(file,printer)” command to send a file to one of
two
possible printers. Attempting to use this function from two processes
at
once causes garbled output, and users don’t care which printer the
output
is sent to. Using any clear pseudocode,
show
how you would write a “safe_print(file)” function using semaphores to print safely
to
any available printer.