The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+21 votes

Consider the resource allocation graph in the figure.

  1. Find if the system is in a deadlock state

  2. Otherwise, find a safe sequence

asked in Operating System by Veteran (59.5k points)
edited by | 1.5k views

2 Answers

+25 votes
Best answer

From the RAG we can make the necessary matrices.

  $R1$ $R2$ $R3$
$P0$ $1$ $0$ $1$
$P1$ $1$ $1$ $0$
$P2$ $0$ $1$ $0$
$P3$ $0$ $1$ $0$
Future Need
  $R1$ $R2$ $R3$
$P0$ $0$ $1$ $1$
$P1$ $1$ $0$ $0$
$P2$ $0$ $0$ $1$
$P3$ $1$ $2$ $0$

$\text{Total}=(2\quad 3\quad 2)$

$\text{Allocated}=(2\quad 3\quad 1)$

$\text{Available}=\text{Total} -\text{Allocated} =(0\quad 0\quad 1)$

$P2 s$ need $(0\quad 0\quad 1 )$ can be met

And it releases its held resources after running to completion

$A=(0\quad 0\quad 1)+(0\quad 1\quad 0)=(0\quad 1\quad 1)$

$P0 s$ need $(0\quad 1\quad 1 )$ can be met

and it releases 

$A=(0\quad 1\quad 1)+(1\quad 0\quad 1)=(1\quad 1\quad 2)$

$P1$ needs can be met $(1\quad 0\quad 0)$

$A=(1\quad 1\quad 2)+(1\quad 0\quad 0)=(2\quad 1\quad 2)$

$P3 s$ need can be met 

So, the safe sequence would be $P2-P0- P1- P3.$

answered by Active (3.5k points)
edited by
what we do if any process need is not matching from need matrix??? and which condition the system is in dead lock...

pllzz explain

Minor mistake in the calculation :

P1 needs can be met (1 0 0)

A=(1 1 2)+(1 1 0)=(2 2 2)

P3 s need can be met 

so the safe sequence would be P2 P0 P1 P3.


@hira If no process meets requirement then we are in an unsafe state. An unsafe state may lead to deadlock.

(deadlock is subset of unsafe state). Sometimes it may not lead to deadlock.  But if there is a safe sequence we are sure that it will never lead to deadlock.

A valuable information.
+13 votes

a) The system is not in deadlock state as there exists a safe sequence.

b)  P2 P0 P1 Pis a safe sequence.

answered by Junior (541 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

39,512 questions
46,664 answers
57,481 users