You are on page 1of 3

Birla Institute of Technology and Science, Pilani Hyderabad Campus

CS F372 (Operating Systems)


st
1 Semester 2017-18 (Mid semester Test)
Solutions Key
------------------------------------------------------------------------
10.10.2017 (6.00pm)

Q.1
monitor DP
{
enum { THINKING; HUNGRY, EATING} state [10] ;
condition self [5];
void pickup (int i) { state[i] = HUNGRY;
test(i); if (state[i] != EATING) self [i].wait ();
}
void putdown (int i) {
Part correct: 3
state[i] = THINKING;
marks
test((i + 8) % 10);
test((i + 2) % 10); Entire: 8 marks
}
void test (int i) {
if ( (state[(i + 8) % 10] != EATING) &&
(state[i] == HUNGRY) &&
(state[(i + 2) % 10] != EATING) ) {
state[i] = EATING;
self[i].signal () ;
}
}

Q.2 Deadlock will be seen in the below execution sequence out of many possible:
S1 S2 S3

P1
P2
P3 3 marks

The Need, allocated and Available matrices will become as shown below:

Allocated Need
P1 0 0 0 P1 1 1 0
P2 0 0 0 P2 0 1 1 5 marks
P3 0 0 0 P3 1 0 1

1 1 1 (1/3)
Available
Running Bankers, one possible safe sequence is: P3, P2, and P1. Hence, by not allowing the other two
processes when one is in Critical section, deadlock is avoided. Some of the other possible safe sequences
are, P1, P2, P3; P1; P3, P2 etc.
3 marks
Q.3 a) The problem was fatal because it could cause a crash. The reason being if both the drivers check
the bowl at a time and find it empty, they will each put a rock and drive through which will cause the
crash. A possible solution is, the Bolivian driver must wait at the entry to the pass until the bowl is
empty, drive through the pass and walk back to put a rock in the bowl. The Peruvian driver must wait at
the entry until the bowl contains a rock, drive through the pass and walk back to remove the rock from
the bowl. Sure enough, his method prevented crashes. If you write the solution using two bowls, it will
also be correct. In one a driver puts a stone and checks the other one to be empty, and then drives the
train. 3 marks
b) The CPU efficiency = CPU usage time / total CPU time (duration)
Here, time quantum is lesser than average process run time and hence, each run of process will require
4/2 process switches. Hence, the overhead (wasting time) will be 1.5X(4/2) = 3 milliseconds. Hence, the
CPU efficiency will then be:

4
= 0.5714 (~ 57%) Ans. 5 marks
(4+3)

If Time quantum is 1.5 ms, then overhead will become 1.5X(4/1.5) = 4 ms, and hence efficiency will
become 4/(4+4) = 0.50 (50%) Ans. 5 marks

Q.4 a) The Gantt chart will be as below:

Idle P3 P2 P1

0 1.5 3.5 10.5 20.5

Average Turnaround Time:

Waiting + Execution for P1 = 20.5 – 0 = 20.5


No partial marking.
Waiting + Execution for P2 = 10.5 -0.5 = 10
Entire 6 marks
Waiting + Execution for P3 = 3.5 -1.5 = 2

ATAT= (20.5 +10+2)/3 = 10.83 ms Ans.

b) The exponential average formula is as given below:

τn = αtn + (1-α) τn-1

τ1 = 0.75X3 + 0.25 X 20 = 7.25 2 marks

τ2 = 0.75X16 + 0.25X7.25 = 13.81


(2/3)
Here, As we considered τ0 = 20, the predicted values were larger than the currently seen (larger) ones,
and also larger than the currently (seen) smaller ones. The constant should be considered as a system
average. Also, the value of alpha matters. 2 marks

Q.5 a) The states through which the two processes will go through is as shown below (ne possibility):

Ready Ready

New New
Running Running

Blocked Suspend
ed

2 marks 2 marks

b) Yes. Timing is crucial to real-time applications. If a thread is marked as real-time but is not bound to
an LWP, the thread may have to wait to be attached to an LWP before running. Consider if a real-time
thread is running (is attached to an LWP) and then proceeds to block (i.e. must perform I/O, has been
preempted by a higher-priority thread, is waiting for a mutual exclusion lock, etc.). While the real-time
thread is blocked, the LWP it was attached to has been assigned to another thread. When the real-time
thread has been scheduled to run again, it must first wait to be attached to an LWP. By binding an LWP
to a real-time thread you are ensuring the thread will be able to run with minimal delay once it is
scheduled again. 1 mark (Yes) + 3 marks for
reasoning
Q.6 a) The Gantt chart is as given below: No partial marking. Entire 6 marks.

P1 P2 P3 P4 P1 P2 Idle P3 Idle P4
CPU CPU
I/O

0 60 62 63 66 126 128 171 172 241 244


Idle I/O

The Gantt chart shows I/O and CPU idle times because of one CPU bound and three I/O bound
processes. Although convoy effect is not very large, if you would have another say, 10 to 15 I/O bound
processes, then the impact (idle times) would have been more.
b) The MLFQ Gantt chart is as shown below:
No partial marking. Entire 4 marks.

P1 P2 P3 P4 P1 P1 P3 P4 P1

0 10 20 30 40 60 70 90 100 110
Average Waiting Time (AWT) = P1 (60) + P2 (10-1) + P3 (60-2) + P4 (80-3) = 204/4 = 51 ms Ans.

CSIS N/B and CMS Remove by 18th Oct 2017 (3/3) I/C (C R Hota)

You might also like