Вы находитесь на странице: 1из 3

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI (RAJ) I Semester 2009-2010

CS C372/IS C362

23/09/2009

OPERATING SYSTEMS Time: 50 Min

TEST I (Close Book) MM: 50

Q1.

Four batch jobs A through D arrive for execution at the times indicated:

Process

Arrival time

Total CPU Burst time

A

0

8

B

1

4

C

3

3+3

D

5

3

The characteristics of each process is listed below:

Process A: Totally CPU bound. Process B: Totally CPU bound. Process C: Executes on CPU for 3 time units and follows it by I/O for another 4 Time units and ends with a CPU burst of 3 units of time. Process D: Totally CPU bound.

For each of the following scheduling algorithm, determine the average waiting and turn

around times. Also draw the corresponding Gantt charts. Ignore context switch overhead.

a) RR (Time Quantum = 4 units)

b) VRR (Time Quantum = 4 units)

c) HRRN

d) Preemptive SJF (SRTF)

[24]

Q2. (a) Suppose N processes with IDs 0, 1, 2, ….,N-1 need to share some critical region of code, which only one at a time is allowed to execute, and where they are required to repeatedly cycle through this critical section in the natural order (0, 1, 2, ….,N -1). If turn is a shared integer variable initialized to zero, and current_pid is the ID of the currently executing process, and each executes the following (pseudo) code, could a race condition occur? Why or why not? Be precise.

while( TRUE )

{

while( turn != current_pid ) /* wait */ ; critical region(); turn = (turn + 1) % N; noncritical region();

}

(b) How many semaphores would be required if a semaphore solution to this problem was used instead? Write the pseudo-code for this.

[12]

P.T.O

Q3. Consider a system with two preemptively scheduled processes. One process executes the WriteA function shown below. The other executes the WriteB function, also shown below. Both functions use kprintf to produce console output. The random function called by WriteA returns a randomly generated nonnegative integer. WriteA and WriteB are synchronized using two semaphores, S a and S b . The initial value of both semaphores is zero. Assume that the individual calls to kprintf are atomic.

WriteA() { unsigned int n,i; while(1) {

WriteB() { while(1) { wait(S b );

n = random(); for(i=0;i<n;i++) { kprintf(‘‘A’’);

kprintf(‘‘B’’); signal(S a );

}

}

}

for(i=0;i<n;i++) {

signal(S b );

}

for(i=0;i<n;i++) { wait(S a );

}

}

a) Consider the following 10-character console output prefixes. (Each prefix shows the first 10 characters printed to the console.) Which of these prefixes could possibly be generated by the two processes running in this system? Justify your answer in each case.

i) ABABABABAB

ii) BABABABABA

iii) AAAAAAAA AA

iv) AAABABABAB

v) AAABBBBAAB

vi) AAAAAABBBB

vii) AAABBBAABB

viii) BBBBBAAAAB

ix) ABABBABABA

x) AAABBBABAB

b) Suppose that the initial value of semaphore S b is 1, rather than 0. Show the 10-character console output prefixes that could be generated in that case, and that could not be generated if the initial value of S b were 0 and are listed in part a.

[13]

Ans 3:

Possible are:

I, iii, vi,vii,x Rest are not possible

(b) ii,v and ix will become possible

Ans2:

(a) No race condition exists

(b) Wait (sem[I]) CS

Signal(sem[(I+1)%N]

N Semaphores are required