0% found this document useful (0 votes)
15 views

Operating System - Weekly Test 04 - Test Paper

Gate

Uploaded by

piyushpandey6980
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Operating System - Weekly Test 04 - Test Paper

Gate

Uploaded by

piyushpandey6980
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

Branch : CSE & IT Batch:Hinglish


WEEKLY TEST – 04
Subject : Operating System
Topic : Process Synchronization / Coordination
Maximum Marks 15

Q.1 to 5 Carry ONE Mark Each


[NAT]
1. Consider a system having ‘n’ resources of same type. P1 P2 P3
All of these resources are shared by five process P0, : : :
P1, P2, P3 and P4 with a peak demand of 7, 8, 9, 10, : : :
and 11, respectively. What could be the maximum x = x + 20 x = x – 50 x = x + 10
: : :
value of ‘n’ to ensure that the system is in deadlock.
: : :
Suppose the process are executed on a uniprocessor
[MCQ]
system running a time-shared operating system. If the
2. Consider the following resources allocation graph. minimum and maximum possible values of x after
complete execution of x are A and B respectively, then
the value of A + B is ___________.

[MCQ]
5. Consider the following code:
Which of the following is correct about above RAG? Process P0 code: Process P1 code:
(a) Both (i) and (ii) has Deadlock while(true) while(true)
(b) Only (i) has Deadlock { {
(c) Only (ii) has Deadlock non-CS(); non-CS();
(d) None of (i) and (ii) has Deadlock. while(true!=0); while(true!=1);
[CS] [CS]
[NAT] true = 1; true = 0;
3. Consider an operating system containing ‘n’ processes } }
each requiring 5 resources. The maximum number of Initially CS value was true = 0. Which of the condition
processes that can be executed without any deadlock if this code is not satisfying?
there are 20 resources is _____. (a) Mutual Exclusion
(b) Progress
(c) Bounded waiting
[NAT]
(d) All of these.
4. Consider three concurrent processes, P1, P2, and P3, as
shown below, which access a shared variable X that
has been initialized to 100.
2

Q.6 to 10 Carry TWO Mark Each

[MSQ]
[MCQ]
6. Consider a system with 3 types of resources R1, R2 and
8. Consider the following code:
R3 in quantity 5, 7, 5 respectively. The allocation and
main ()
max matrices are given as follows:
int a = 0;
Allocation
int b = 0;
R1 R2 R3
begin
P1 2 1 0
Parbegin
P2 1 2 1
thread P();
P3 0 2 2
thread Q();
P4 1 1 1
Parend;
end;
Max
R1 R2 R3
thread P(); threadQ();
2 3 3 begin begin
2 3 2 a = 1; /*statement 1*/ b = 4; /*statement 3*/
3 2 3 b = b + a; /*statement2*/ a = a + 5; /*statement 4*/
3 3 2 end; end;
Which of the following safe sequences are possible?
(a) P4 P2 P1 P3 Suppose a process has 2 concurrent threads; one thread
(b) P2 P4 P3 P1
executes statement 1 and 2 and other thread executes
(c) P2 P1 P4 P3
statement 3 and 4. What are the possible values of
(d) P2 P4 P1 P3
variable ‘a’ and ‘b’ when the code finishes execution?
(a) a = {1, 5, 6}
b = {10, 4, 5}
[MCQ]
(b) a = {1, 5, 6}
7. Consider X, Y, Z are shared semaphore on following
b = {1, 4, 5}
three concurrent processes:
(c) a = {1, 6}
b = {10, 4, 5}
Process-1 Process-2 Process-3
(d) a = {1, 6}
P(X) P(Y) P(Z)
b = {1, 4, 5}
P(Z) Print “B” P(X)
Print “A” Print “E” Print “C”
Print “D” V(X) Print “F” [MCQ]
V(Y) V(Z) 9. Consider program for P1 and P2:
If these processes run concurrently and possible P1() P2()
outputs are CFBEAD, ADCFBE, ACFDBE. What
{ {
could be the initial value of X, Y and Z. So that above
outputs are possible? P(m); P(n)
(a) X = 2, Y = 0, Z = 1 x++; y++;
(b) X = 2, Y = 0, Z = 2 P(n); P(m);
(c) X = 1, Y = 0, Z = 2
(d) X = 2, Y = 0, Z = 1 y++; x++;
V(n); V(m);
V(m); V(n);
} }
3

If m and n are binary semaphore variable whose values


are initially initialized to 1. x and y are shared resources
whose values are initialized to 0.
Which of the following holds by above process?
(b)
(a) Deadlock, and No mutual exclusion
(b) No deadlock, and no race condition.
(c) Mutual exclusion and no deadlock.
(d) Deadlock, mutual exclusion.

[MCQ]
10. Consider the following code:
begin
S1 ;
Parbegin
(c)
S2;
S3;
begin S4; S5; end
Parend;
S6 ;
(d) None of these.
Which of the following is correct precedence graph for
the above code?

(a)
4

Answer Key
1. (40) 6. (b, d)
2. (d) 7. (b)
3. (4) 8. (c)
4. (180) 9. (d)
5. (b) 10. (b)
5

Hints and Solutions

1. (40) P3, P2, P1


The avoid the deadlock in a system, minimum After executing processes in each of these sequences,
resources required are: we will get
n A = 50 and B = 130
No. of resources > ∑ ( max− need(i)−1) +1 So, A + B = 180.
i=0
To make the system go into deadlock, subtract one 5. (b)
extra resource from each process. The above code behaving similar to strict alternation.
Po → 6 Thus,
P1 → 7 Mutual exclusion and bounded waiting are satisfied.
P2 → 8 Progress is not satisfied here as we are just focused
P3 → 9 on the true variable not on the interest of the process
P4 → 10 to enter the critical section or not.
In any process gets one resources, so the system will
become deadlock free. So in order to ensure 6. (b, d)
deadlock, there must be 6 + 7 + 8 + 9 + 10 = 40 From the given allocation and max matrices, need
Therefore, maximum value of n = 40. matrix can be computed as:
R1 R2 R3
2. (d) P1 0 2 3
There is no deadlock in both RAG. P2 1 1 1
In (i) Process will be executed in following order P3 3 0 1
P3→ P2→ P1 P4 2 2 1
In (ii) Process will be executed in following order
Availability = 1, 1, 1
P2→ P4→ P3→ P1
Only P2’s request can be fulfilled.
After P2 is completed.
Available = 2, 3, 2.
3. (4)
Now, only P4 request can be fulfilled.
There is no deadlock in both RAG. After P4 is completed.
In (i) Process will be executed in following order Available = 3, 4, 3
P3→ P2→ P1 Now, any of P1 and P3 can be serviced.
In (ii) Process will be executed in following order So, safe sequences are
P2→ P4→ P3→ P1 P2 P4 P1 P3 and P2 P4 P3 P1
∴ option b, d are correct.
4. (180)
Total possible execution sequences are 7. (b)
P1, P2, P3 If we take X = 1, Y = 1, then after process – 1 or
P1, P3, P2 process – 3.
P2, P1, P3 If both are concurrently running, then both of the
P2, P3, P1 processes will block and will stuck in deadlock
P3, P1, P2 situation.
6

If we take X = 2, Z = 1, Y = 0 or X = 1, Y =0, Z = 2 → Preempted


then only one of the output above mentioned will P2()
print. 1. P(n)
An X = 2, Y = 0, Z = 2 if either process-1 or process- 2. Y++
3 starts, it will set value to X=1, Y=0, Z=1 and if P(m) //waiting for m to become 1
either process want to interrupt then it will set values → Preempted
to X-0, Y-0, Z-0 and then output will be printed. P1() //arrived again
3. P(n) //waiting for n to become 1
8. (c) Thus, it creates deadlock.
for variable ‘a’: There is mutual exclusion.
I: a = 1 Therefore, option (d) is correct.
a=1+5=6
II: a = 0 + 5 = 5
a=1 10. (b)
Possible values of ‘a’ {1, 6} Precedence graph for given code is:
for variable ‘b’:
I: b = 0 + 1
b=4
II: b = 4
b=4+1=5
b=4
III: b = 4 + 6 = 10
Possible values of ‘b’ {4, 5, 10}

9. (d)
P1()
1. P(m) therefore, option (b) is correct.
2. x ++

For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if

PW Mobile APP: https://smart.link/7wwosivoicgd4

You might also like