CMPUT379--Operating System Concepts
Assignment I
Winter 2001
Due Date: Monday February 12, 2001
Submit your solutions to the instructor (in class) in printed form (hand
written answers are not acceptable)--with the exception of neat, hand-drawn
diagrams, if any. A print-out of a text file (properly formatted and with
2 cm margins) is acceptable, but a nice presentation (using a standard
documentation tool) will make your work easier to read and mark.
Concise well-written answers are expected. A good source of background
material is the first six chapters of your text by Silberschatz and Galvin,
and your recent laboratory exercises.
1. What two advantages do threads have over multiple processes? What
major disadvantage do they have? Suggest one application that would benefit
from the use of threads, and one that would not. Explain why.
2.
As presented in Section 4.4 of the text, the Pascal-like pseudo code
there uses a maximum of N-1 of the available N buffers.
Convert that to C-style pseudo code AND do so in such a way that now
all N buffers can be correctly used. Build a solution that handles
the general case (K-producers, M-consumers), perhaps?
The text considers only the case K=M=1, you should handle K>=1 and
M>=1.
Declare and initialize all variables and semaphores you use.
Show the details of buffer index incrementation.
Your answer must include specification of P()/V() synchronization primitives
for a binary semaphore [perhaps using busy waiting], and wait()/free()
primitives for a counting semaphore. Use these primitives appropriately to
protect all shared resources and shared variables you use.
3. Provide simple busy-wait P() and V() synchronization primitives
in C-pseudo code. Use them to solve the "Burger-Maker Problem". Common
ingredients in a burger are: a pattie, a bun and cheese. Consider
a system with three "dispenser" processes sitting at a conveyor;
one has a supply of patties, one a supply of buns and one a supply of cheese.
A fourth process, the cook, has a supply of all three and places any two
different ingredients, selected randomly, on the conveyor. The dispenser
with the missing third ingredient then completes the burger. Assuming
that all supplies of pattie, bun and cheese are limitless, write C-pseudo
code to implement and synchronize the activities of the cook and the dispensers.
Be sure that only the dispenser who is currently garnishing and wrapping
the burger signals to the cook to produce more ingredients. Here
the cook is the"producer" and the dispensers are "consumers" in the classic
producer/consumer problem sense.
4. Write a working C-program that accepts an arbitrary number
of input lines of arbitrary length. Every line will contain Unix
commands, each separated by a semicolon. As each line is read it
is passed to a child process. That child process in turn creates
as many children as necessary to execute concurrently all the Unix commands
in the line. For example, an input line might be "date;ls -dg *;sleep 100;ps
-aux". In this case the parent will create a child to accept the
line and in turn create four children of its own to process the commands.
Comment your program appropriately.
Submit a listing of your program, written as elegantly as you can.
Describe the design issues you faced and how you addressed them.
Show output from several test suites, enough to demonstrate the
correctness and robustness of your program. Emphasise your
attempts to find command sequences that break your program. Document
your findings.
Copyright © Department of Computing Science.
All rights reserved.
Last update:Jan 22 06:44:52 2001