CS 162

MIDTERM 1

FALL 1996

Prof. Alan Jay Smith

You have until the end of class for this exam. The exam is closed book. All

answers should be written on the exam paper. Anything that we can't read or

understand won't get credit. Any question for which you give no answer at all

will receive 25% partial credit. Please answer in standard English; illiterate or

illegible answers to essay questions will lose credit. Please watch the front

board for corrections and other informations. This exam has 6 questions on

7 pages and is in two parts.

Problem #1

The state of a system is as shown. (There are 3 processes, A, B and C. There are two resources.)

process Allocated Max_need

A 10 15 30 20

B 0 30 40 75

C 20 10 30 35

available: 15 30

Determine if this system is in a safe state. Show your work (12)

Problem #2

Assume that the arrival times and run times of jobs are as follows:

job arrival-time run-time

CS 162, MIDTERM 1, FALL 1996

CS 162MIDTERM 1FALL 1996 Prof. Alan Jay Smith 1

A 0 5

B 0.5 3

C 1.5 0.5

a. Show the sequence of executions and compute the mean flow time for the following scheduling algorithms

(15):

i. FIFO

ii. SET (Q--->0; i.e. processor sharing)

iii. SRPT

b. Now assume that the system is non-preemptive. You have future knowlege. What the schedule (of all

possible schedules, not just the algorithms from part (a) that minimizes the mean flow time? (5)

c. Still assuming that the system is non-preemptive, and you have future knowlege, let there be two CPUs

(processors). What is the schedule that minimizes the mean flow time now? Compute the mean flow time. (5)

d. Now assume that preemption is permitted, and that there are two processors. Show the schedule that

minimizes the time to completion (i.e. until all jobs are done) (5)

Problem #3

Suppose C is augmented with P,V, and Conditional-P. Conditional P tries to decrement the semaphore, if it is

not legal (i.e. Sem = 0), then it returns FALSE, if it is legal, it does it and returns TRUE.

a) What is useful about Conditional-P? (6)

b) Can it be used to avoid deadlocks in all cases? (Why/Why not, be careful to state your assumption). (6)

Problem #4

Assume a Coca-Cola machine exists. Assume there are many people who drink Coca-Cola and many people

who stock the machine with Coca-Cola (21).

Write functions for the 'Stockers' and the 'Drinkers', using P() and V().

Properly synchronize your code so that only *one* stocker or drinker can have access to the coke machine at

CS 162, MIDTERM 1, FALL 1996

Problem #2 2

##### Document information

Uploaded by:
shaina_44kin

Views: 918

Downloads :
0

Address:
Computer science

University:
Central University of Jammu and Kashmir

Subject:
Operating Systems

Upload date:
02/04/2013