Professional Documents
Culture Documents
COMPUTER SCIENCE 97505 80349, 97505 80329 UNIT - II (6)
OS Problems
9.A single processor system has three resource types X, Y and Z, which are shared by three processes.
There are 5 units of each resource type. Consider the following scenario, where the column alloc denotes
the number of units of each resource type allocated to each process, and the column request denotes the
number of units of each resource type requested by a process in order to complete execution. Which of
these processes will finish LAST?
alloc request
XYZ XYZ
P0 1 2 1 103
P1 2 0 1 012
P2 2 2 1 120
(A) P0
(B) P!
(C) P2
(D) None of the above, since the system is in a deadlock
Solution: A single processor system has three resource types X, Y and Z, which are shared by three
processes. There are 5 units of each resource type.
Solution:
Compaction: A possible remedy to the problem of external fragmentation iscompaction. The idea is to
move all processes towards one end of memory and all the free blocks of memory towards the other end.
so ans B.181 .
1. repeat
2. P(mutex)
3. { Critical Section }
4. V(mutex)
5. forever
The code for P10 is identical except that it uses V(mutex) in place of P(mutex). What is the largest number
of processes that can be inside the critical section at any moment?
a. 1 b. 2 c. 3 d. None of these
wait(m[i]);
………….
release(m[i]);
Solution: Initially only P0 can go inside the while loop as S0 = 1, S1 = 0, S2 = 0. P0 first prints ‘0’ then,
after releasing S1 and S2, either P1 or P2 will execute and release S0. So 0 is printed again.
Answer:a.Atleast Twice
Process P:
1. while(1)
2. {
3. W:
4. print '0';
5. print '0';
6. X:
7. }
Process Q:
1. while(1)
2. {
3. Y:
4. print '1';
5. print '1';
6. Z:
7. }
Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will
always lead to an output string with ‘001100110011’?
Signal(S)
{
S++;
}
Initially, we assume S = 1 by comparing Wait(s) with Wait(1) we get s=1.
T = 0 to support mutual exclusion in process P and Q.
Since S = 1, only process P will be executed and wait(S) will decrement the value of S. Therefore, S = 0.
At the same instant, in process Q, value of T = 0. Therefore, in process Q, control will be stuck in while
loop till the time process P prints 00 and increments the value of T by calling the function V(T).
While the control is in process Q, semaphore S = 0 and process P would be stuck in while loop and would
not execute till the time process Q prints 11 and makes the value of S = 1 by calling the function V(S).
This whole process will repeat to give the output 00 11 00 11 …