You are on page 1of 9

Name:- Rakesh Kumar Nayak

Roll no:- 19csu239

.Process Synchronization and Deadlock Solution


Assignment

Q1 : Five processes are competing for resources R0, R1, R2, and R3 where (R1, R2, R3, R4)
=(6, 4, 4, 2). The maximum claim of these processes and the initial resources allocated to these
processes, are given in the following space:

Solution:-
a) Does this initial allocation lead to a safe state? Explain with reason.
Ans;- Yes initial allocation is in safe state.

b) If P2 requests two instances of R1, one instance of R3, and one instance of R4, check
whether the system is still in safe state.
Ans:- No, resource exceed the maximum need,so there can be unsafe
sequence.

c) If it is, find out the safe sequence of process execution.


Ans:- safe seq:-P3 P1 P4 P5 P2

Q2 : A system consists of three processes P1, P2, and P3. There is a single resource type Printer
but with four instances. Each process declares the maximum resource demand of 3 instances. Is
deadlock possible in this situation?

Ans:- No deadlock is not possible in these case since there are 4 instance of
resources, and its need three instances for each process P1,P2,P3. There is
available instance , so deadlock is not possible in this case.

Q3 : There are four processes sharing a semaphore for synchronizing a shared variable. The
semaphore is guarding the CS of the processes where they update the shared variable. Initially,
the value of the semaphore is three. The actions taken by the processes in time sequence are
given below:

Show and explain the current and updated value of a semaphore at every time instant and the
processes in the wait queue.

Ans:- -
P operation also called as wait operation decrements the value of
semaphore variable by 1.
 V operation also called as signal operation increments the value of
semaphore variable by 1.
At time T1,P1 is increment by 1
At time T2,P2 is increment by 2
At time T2,P3 is increment by 3
At time T3,P4 is increment by 4

8 P operations and 3 V operations are performed on S


 Thus,
Final value of semaphore variable S
= 11 – (3x 1) + (8 x 1)
= 11 – 3 + 8
=0

Q4: In a system, the following state of processes and resources is given:


R2->P1, P1->R2, P2->R3, R1->P2, R3->P3, P3->R4,
P4->R3, R4->P4, P4->R1, R1->P5
Draw a RAG and wait-for graph for the system, and check the deadlock condition.
Ans:-

No,there is no deadlock in this case.


Q5: There is a dining hall of capacity of 10 people at the most in a restaurant where families
come to enjoy delicious food. On weekends, however, there is a great crowd in the restaurant. A
person would be entertained only if there is a vacant chair. If all the seats are full, it means that
there is a single family of 10 members enjoying the dinner. In this case, the person has to wait
until the family leaves. Write a synchronization solution using semaphores for the customers
entering and leaving the dining hall.

Ans:- Synchronisation solution for the customers entering and leaving the
dining hall.
Let there be ten chair C1,C2,C3,C4,C5,C6,C,C8,C9,C10

We use a semaphore to represent a vacant chair and this truly acts as a


solution of the Dining Philosophers Problem. Wait and Signal
operations will be used , for picking a chair wait operation can be
executed while for releasing a chair signal semaphore can be executed.

 wait( S )  
{  
while( S <= 0) ;  
S--;  
}  
  
2. signal( S )  
{  
S++;  
}  

Let's modify the above code of the Dining chair Problem by using
semaphore operations wait and signal, the desired code looks like

void restaurant
 {  
 while(1)  
  {  
   Wait( take_chairC[i] );  
   Wait( take_chairC[(i+1) % 10] ) ;  
   . .  
   . EATING dinner  
   .  
   Signal( put_chairC[i] );  
   Signal( put_chairC[ (i+1) % 10] ) ;  
   .  
   . THINKING  
  }  
}  

Q6: Consider a system with the following information. Determine whether the system is in a
deadlock situation.
Q7: Can there be a deadlock in the main memory?

Q8: Consider a system with the following information. Determine whether the system is in safe
state.
Total_Res

Ans:-
Q9: A buffer has 10 slots. The initial value of empty = 10 and full = 0. What will be the value of
empty and full in the following conditions?
( a) The producer has inserted five items and the consumer is not able to consume.
Ans:- empty = 5, full= 5

( b) The producer has inserted five more items and the consumer is not able to consume.
Ans:- empty = 0, full = 10

( c) The producer has produced three more items but cannot insert as the buffer is full.
Ans:- empty = 0, full = 10

(d) The consumer has consumed five items.


Ans:- empty = 5 , full = 5
Q10: A working couple has three babies. The babies cannot be left unattended: Any one from the
couple must be present at home for the babies. Write a solution for synchronizing the parents
with the babies.
Ans:- Using semaphores following code look like,
Let baby represent by B[i],

void couples 
 {  
 while(1)  
  {  
   Wait( take_babyB[i] );  
   Wait( take_babyB[(i+1) % 3] ) ;  
   . .  
   .caretaking 
   .  
   Signal( put_babyB[i] );  
   Signal( put_babyB[ (i+1) % 3] ) ;  
   .  
   . T
  }  
}  

You might also like