Sie sind auf Seite 1von 3

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI

Second Semester 2003-2004


Course Title : OPERATING SYSTEMS Course No CS C372 & IS C362
Component : Test I (Makeup) Open Book Component
Weightage : 10% Max Marks: 10 Date : 15-03-2004
Note: Attempt all the Questions. Start each answer from a fresh page.

Question #1 (2 Marks)
Assume that a context switching may occur between any two-machine
instructions. Initially, address x contains 5 and address y contains 20, Assembly-
language code is given for two threads, T1 and T2 which execute concurrently.
Basically, T1 does "y:= y - x" and Y2 does "x := y - 1".

T1 T2
LOAD x, r1 LOAD y, r1
LOAD y, r2 DE C r1
SUB r2, r1 STORE r1, x
STORE r2, y

What are the possible pairs of final values of x and y (i.e.,the values after both threads
have finished)? For example, your answer could be something like: x = {1, 2, 3 . . .} and
y ={1, 2,. . . }.

Answer
X = {14,19}
Y= {1,15}

Question #2 (5 Marks)
A multilevel feedback queue algorithm works with the following condition
Number of queues 3 (Q1,Q2 and Q3)
Scheduling algorithm Q1 R R, Q2 preemptive priority Q3 FCFS
Method used to upgrade a process No upgrading among queues
Method to demote a process Q1ÆAfter 2 units of time, Q2Æ When the Priority
becomes 0 (Priority of the process reduced by 1 for every 1 units of execution in CPU),
Q3ÆThe Process who came first to the queue will get the first chance.
Method used to determine which queue a process will enter
P1, P3 & P5 are entering through Queue #2 (Q2)
P2 & P4 are entering through Queue #1 (Q1)

Process T.CPU burst CPU burst I/O burst Priority Arrival time
P1 14 7 6 6 0
P2 13 9 2 5 1
P3 7 4 8 4 3
P4 13 8 4 4 6
P5 8 5 5 3 9
Calculate Average waiting time, average turn around time, and CPU utilization

Operating Systems (CS C372 & IS C362) Test #1 1


P1 P2 P2 P1 P2 P2 P4 P4 P1 P3 P4 P4 P1 P2 P3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
P5 P5 P1 P2 P3 P4 P4 P1 P2 P3* P5 P4 P4* P1* P2
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
P2* P5 P4 P4 P2 P2 P1 P1 P2 P2* P3 P4 P1 P1 P3
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
P4 P4** P3** P1 P1 P5* P1** I D L E P5 P5 P5**
46 47 48 49 50 51 52 53 54 55 56 57 58 59

Turn around time

P1 (52 – 0) = 52
P2 (40 – 1) = 39
P3 (48 – 3) = 45
P4 (47 – 6) = 41
P5 (59 – 9) = 50
Average turn around time = (52+39+45+41+50)/5 = 227/5 = 45.4

Waiting time

P1 (52 – 0 – 6 – 14) = 32
P2 (40 – 1 – 2 – 13) = 24
P3 (48 – 3 – 8 – 7) = 30
P4 (47 – 6 – 4 – 13) = 24
P5 (59 – 9 – 5 – 8) = 37
Average waiting time = (32+24+30+24+37)/5 = 147/5 = 29.4

CPU utilization = 55/59 = 93.22 %

Question #3 (3 Marks)

Consider the following test program for an implementation of join. When parent thread
calls join on a child thread the parent does the following
1. If the child is still running the parent blocks until the child finishes
2. If the child has finished the parent continues to execute without blocking.

int x=5;
pthread_t tid[25];

void main()
{ void *fun1(void *a)
int i,j=0; {
for(i=0;i<3;i++) { x = x /2 ;
if(fork()) { x=x – 3;

Operating Systems (CS C372 & IS C362) Test #1 2


x=x+5; x=x*3;
pthread_create(tid[i],NULL,fun1,0); }
x = x+10;
}
else {
x = x – 5; void *fun2(void *a)
pthread_create(tid[i],NULL,fun2,1); {
x=x - 2; x = x /4 ;
} x=x + 2;
x=x + 20; x=x*3;
} }
for(i=0;i<3;i++) {
pthread_join(tid[i]);
}
printf(“%d\n”,x);
}

(A) Assume that the scheduler run threads in Round Robin with no implicit
time slicing (i.e. non-preemptive scheduling), priorities are ignored, and threads
are placed on queues in FIFO order. How many different copies of variable x will
be created? What will be the values of x (all copies of x) after execution?
Answer
8 copies of x will be available
Parent’s X value 327,Child1’s X value 138,Child2’s X value 99,
Child3’s X value 72,Child4’s X value 72,Child5’s X value 54
Child6’s X value 54,Child7’s X value 39

Operating Systems (CS C372 & IS C362) Test #1 3

Das könnte Ihnen auch gefallen