0% found this document useful (0 votes)
44 views3 pages

Solution

Uploaded by

f20220233
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views3 pages

Solution

Uploaded by

f20220233
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI, DUBAI CAMPUS

DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI


FIRST SEMESTER 2024 – 2025
DEPARTMENT OF COMPUTER SCIENCE

COURSE : Operating Systems (CS F372) WEIGHTAGE : 15% (15 Marks)


COMPONENT : Quiz 2 (Open Book) DURATION : 20 Minutes
DATE/DAY : 22-11-2024, F4 Questions: 7, Pages: 2
Name: ID:

Instruction: Read the questions carefully and answer all questions with the most appropriate answer

1. An operating system contains 3 processes each requiring 2 units of resource R. The [1]
minimum number of units of R such that no deadlocks will ever arise is:
a) 3 b) 5 c) 4 d) 6
Solution:

Answer: C
In the worst case, if each process holds one unit of resource, for that total three will be re -
quired. 1 more unit can cater to maximum need of any one of these processes and com-
plete it. The resources released by that process will cater to needs of other two process. So
minimum units required to avoid deadlock is 3+1 = 4.
2. Let A be a counting semaphore variable. Its value at some point in time during its usage is [1]
-2. What do you infer from this?
Solution:
Two processes are waiting on it
3. Let a semaphore variable X be used to provide exclusive access to a single instance re- [1]
source. Identify its initial value if
a) X is a binary semaphore
b) X is a counting semaphore
Solution:
1, 1
4. Suppose A and B are two processes that are concurrently executing. They share a common [2]
variable X and use a shared binary semaphore S. The initial value of S is 1 and X is set to
5.
Process A Process B
int Y; int Z;
wait(S); wait(S);
Y = X*2; Z = X+1;
X = Y; X = Z;
signal(S); signal(S);

a) How many different values of X are possible after both processes finish executing
once?
b) What are the different values of X?
Solution:
The semaphore S ensures that, once begun, the statements from either process execute
without interrupts. So now the possible ways in which statements from A and B can be
interleaved are: Y = X*2; X = Y; Z = X+1; X = Z; X = 11
Z = X+1; X = Z;Y = X*2; X = Y; X = 12
a) 2
b) 11, 12
1
5. A computer has three resource types designated as A, B and C. All the resource types [2]
have one instance each. Three processes designated X, Y and Z run on the computer and
each makes periodic use of two of the three resources as follows:
 Process X acquires A, then B, uses both and then releases both.
 Process Y acquires B, then C, uses both and then releases both.
 Process Z acquires C, then A, uses both and then releases both.
If any two of these processes are running simultaneously on a machine, can a deadlock
occur? Justify. [Note proper justification alone will carry credits]

Solution:
Deadlock is not possible since one of the two processes will always be able to run to
completion releasing the resources and then the other process can run to completion
6. In a time sharing operating system, is there a possibility of deadlock occurring involving [2]
the CPU as a resource? Justify. [Note proper justification alone will carry credits]
Solution:

No, there is no possibility of deadlock occurring involving the CPU as a resource. The
CPU can be preempted after the time quanta expires or when a process completes its
execution before the expiry of the time quanta which eliminates one of the four
preconditions for deadlock.
7. Consider the following snapshot of the system resource allocation state with respect to [6]
Process Pi and Resource Rj. Apply Banker’s algorithm to check safety of the system.

Allocation Max. requirement Available


Proc R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4
P0 0 0 1 2 0 0 1 2 1 5 2 0
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6
P3 0 6 2 2 2 6 5 2

a) Is the system currently in a safe state? __________


b) If yes, give all possible safe sequences. Otherwise list the processes that are not
completable

Solution:

 need matrix [2M]


 updating available (work) vector [1M]
 6 safe sequences (6 *0.5 = 3 M)

Allocation Max. requirement Need Available

Proc R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4 R1 R2 R3 R4

P0ü 0 0 1 2 0 0 1 2 0 0 0 0 1 5 2 0

P1 1 0 0 0 1 7 5 0 0 7 5 0 1 5 3 2

P2ü 1 3 5 4 2 3 5 6 1 0 0 2 2 8 8 6

P3 0 6 2 2 2 6 5 2 2 0 3 0

P4 0 0 1 4 0 6 5 6 0 6 4 2

2
Seq: <P0, P2, Remaining processes in any order results in safe sequences>

Total 6 safe sequences.


<P0, P2, P1, P3, P4>, <P0, P2, P1, P4, P3>, <P0, P2, P3, P4, P1>, <P0, P2, P3, P1, P4>,
<P0, P2, P4, P3, P1>, <P0, P2, P4, P1, P3>

********** ALL THE BEST *********

You might also like