Numerical Solved by Banker’s Algorithm

Q2. Consider the table given below for a system, find the need matrix and the safety sequence, is the request from process P1(0, 1, 2) can be granted immediately.

Resource – 3 types

A – (10 instances)

B – (5 instances)

C – (7 instances)

Process

Allocation

Maximum

Available

Need

P0

P1

P2

P3

P4

A

B

C

0

1

0

2

0

0

3

0

2

2

1

1

0

0

2

A

B

C

7

5

3

3

2

2

9

0

2

2

2

2

4

3

3

A

B

C

3

3

2

A

B

C

7

4

3

1

2

2

6

0

0

0

1

1

4

3

1

Solution: Banker’s Algorithm

Step 1:

Safety for process P0

need0 = (7, 4, 3)

If need0 ≤ Available

if [(7, 4, 3) ≤ (3, 3, 2)] (false)

Process P0 must wait.

Step 2:

Safety for process P0

need1 = (1, 2, 2)

if needi ≤ Available

if [(1, 2, 2) ≤ (3, 3, 2)]

Pi will execute.

Available = Available + Allocation

= (3, 3, 2) + (2, 0, 0)

= (5, 3, 2)

Step 3:

Safety for process P2

need2 = (6, 0, 0)

if need2 ≤ Available

if [(6, 0, 0) ≤(5, 3, 2)] (false)

P3 will execute.

Available = Available + Allocation

= (5, 3, 2) + (2, 1, 1)

= (7, 4, 3)

Step 5:

Safety for process P4

need4 = (4, 3, 1)

If need4 ≤ Available

If [(4, 3, 1) ≤ (6, 4, 3)]

P4 will execute.

Available = Available + Allocation

= (7, 4, 3) + (0, 0, 2)

= (7, 4, 5)

Step 6:

Safety for process P0

                need0 = (7, 4, 3)

if need0 ≤ Available

if [(7, 4, 3) ≤ (7, 4, 5)]

P0 will execute.

Available = Available + Allocation

= (7, 4, 5) + (0, 1, 0)

= (7, 5, 5)

Step 7:

Safety for process P2

need2 = (6, 0, 0)

if need2 ≤ Available

if [(6, 0, 0) ≤ (7, 5, 5)]

P2 will execute.

Available = Available + Allocation

= (7, 5, 5) + (3, 0, 2)

= (10, 5, 7)

 

Safety Sequence = <P1, P3, P4, P0, P2>

2 thoughts on “Numerical Solved by Banker’s Algorithm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s