You are on page 1of 1

Manipal University Jaipur

Department of Information Technology


CS1401: Operating System
Assignment on Process Synchronization and Deadlock
Deadline: 27/04/2020
Q1: Consider a shared variable x, initialized to zero, is operated on by five concurrent processes
A, B, C, D, E as follows. Each of the processes A and B reads x from memory, increments by
one, stores it to memory, and then terminates. Each of the processes C, D and E reads x from
memory, decrements by two, stores it to memory, and then terminates. Each process before
reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V
operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized
to three. What is the maximum possible value of x after all processes complete execution?
Justify your answer through proper explanation.
Q2: Suppose we want to synchronize four processes W, X, Y and Z using two binary semaphore
S and T. We want output string: 001100110011. Check following four statement, explain
clearly which statement generate desired output and which are not generating above output.
Statement W X Y Z Semaphore
1 Wait(S) Signal(S) Wait(T) Signal(T) S, T = 1
2 Wait(S) Signal(T) Wait(T) Signal(S) S=1, T=0
3 Wait(S) Signal(T) Wait(T) Signal(S) S, T =1
4 Wait(S) Signal(S) Wait(T) Signal(T) S=1, T=0

Q3: Consider a system with the following current resource-allocation state: There are five
processes P0, P1, P2, P3, P4 and three resource types: A, B, and C. For each process, the current
allocation and the maximum required allocation are given by the ALLOCATION and MAX
matrices. The current available resources are given by the AVAILABLE vector.
PROCESS ALLOCATION MAX AVAILABLE
A B C A B C A B C
P0 1 1 2 4 3 3 2 1 0
P1 2 1 2 3 2 2
P2 4 0 1 9 0 2
P3 0 2 0 7 5 3
P4 1 1 2 11 2 3
a) Determine the total amount of resources of each type?
b) What is the “NEED” matrix?
c) Determine whether the system is in safe state using Bankers Algorithm?

Q4: Consider a system with 3 processes that share 4 instances of same resources type. Each
process can request a max of ‘k’ instances. Find the largest value of ‘k’ that will always avoid
deadlock. Explain your answer clearly.
Q5: Write Peterson’s algorithm and show that it satisfies all the requirements of a mechanism
to control access to a critical section.

You might also like