0% found this document useful (0 votes)
462 views8 pages

Problems Using Bankers Algortihm: Operating System

The document describes a bankers algorithm problem involving 5 processes - P0, P1, P2, P3 and P4. It provides the allocation matrix, maximum matrix and available resources. It then asks: 1) Write the need matrix and check if the system is in a safe state. The need matrix is provided and the system is found to be in a safe state with the safe sequence as <P0 P1 P2 P3 P4>. 2) It provides another allocation matrix and asks to check if requests from P1 and P4 can be granted. The need matrix is provided. The request from P1 is found to be granted but the request from P4 is not granted as

Uploaded by

Shreya
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)
462 views8 pages

Problems Using Bankers Algortihm: Operating System

The document describes a bankers algorithm problem involving 5 processes - P0, P1, P2, P3 and P4. It provides the allocation matrix, maximum matrix and available resources. It then asks: 1) Write the need matrix and check if the system is in a safe state. The need matrix is provided and the system is found to be in a safe state with the safe sequence as <P0 P1 P2 P3 P4>. 2) It provides another allocation matrix and asks to check if requests from P1 and P4 can be granted. The need matrix is provided. The request from P1 is found to be granted but the request from P4 is not granted as

Uploaded by

Shreya
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/ 8

Operating System

PROBLEMS USING BANKERS ALGORTIHM

Q1.

Process Allocation Max


A B C D A B C D
P0 0 2 1 2 0 3 2 2
P1 1 1 0 2 2 7 5 2
P2 2 2 5 4 2 3 7 6
P3 0 3 1 2 1 6 4 2
P4 2 4 1 4 3 6 5 8

Available
A B C D
2 5 3 2

A) Write the need matrix


B) Is the system safe? If yes write the sequence.
Need = Max – Allocation

Process Need
A B C D
P0 0 1 1 0
P1 1 6 5 0
P2 0 1 2 2
P3 1 3 3 0
P4 1 2 4 4

The System is in safe state. Sequence is < P0 P1 P2 P3 P4 >


need <= work
P0 --> 0110 <= 2532
w = 2532 + 0212 = 2744
P1 --> 1650 <= 2744
w = 2744 + 1102 = 3846
Operating System

P2 --> 0122 <= 3846


w = 3846 + 2254 = 510910
P3 --> 1330 <= 510910
w = 510910 + 0312 = 5131012
P4 --> 1244 <= 5131012
w = 5131012 + 2414 = 7171116
Q2.

Process Allocation Max


A B C D A B C D
P0 2 0 0 1 4 2 1 2
P1 3 1 2 1 5 2 5 2
P2 2 1 0 3 2 3 1 6
P3 1 3 1 2 1 4 2 4
P4 1 4 3 2 3 6 6 5

Available
A B C D
3 3 2 1

Given: A-12, B-12, C-8, D-10


A) What is the content of the need matrix
B) If a request from process P1 arrives for (1,1,0,0) can the request be granted?
C) If a request from process P4 (0,0,2,0) arrives, can it be granted?
Need = Max - Allocation

Process Need
A B C D
P0 2 2 1 1
P1 2 1 3 1
P2 0 2 1 3
P3 0 1 1 2
P4 2 2 3 3
Operating System

The system is in safe state. Safe Sequence is < P0 P3 P4 P1 P2 >


need <= work
P0 --> 2211 <= 3321
w = 3321 + 2001 = 5322
P1 --> 2131 <= 5322 ×
P2 -->0213 <= 5322 ×
P3 --> 0112 <= 5322
w = 5322 + 1312 = 6634
P4 --> 2233 <= 6634
w = 6634 + 1432 = 71066
P1 --> 2131 <= 71066
w = 71066 + 3121 = 101187
P4 --> 0213 <= 101187
w = 101187 + 2103 = 1212810
Request from P1 (1,1,0,0)
Request <= Need -> 1100 <= 2131
Request <= Available -> 1100 <= 3321
Allocation = Allocation + Request = 3121 + 1100 = 4221
Need = Need – Request = 2131 – 1100 = 1031
Available = Available – Request = 3321 – 1100 = 2221

Process Allocation Max Work Need


A B C D A B C D A B C D A B C D
P0 2 0 0 1 4 2 1 2 2 2 2 1 2 2 1 1
P1 4 2 2 1 5 2 5 2 1 0 3 1
P2 2 1 0 3 2 3 1 6 0 2 1 3
P3 1 3 1 2 1 4 2 4 0 1 1 2
P4 1 4 3 2 3 6 6 5 2 2 3 3
Operating System

need <= work


P0 --> 2211 <= 2221
w = 2221 + 2001 = 4222
P1 --> 1031 <= 4222 ×
P2 --> 0213 <= 4222 ×
P3 --> 0112 <= 4222
w = 4222 + 1312 = 5534
P4 --> 2233 <= 5534
w = 5534 + 1432 = 6966
P1 --> 1031 <= 6966
w = 6966 + 4221 = 101187
P4 --> 0213 <= 101187
w = 101187 + 2103 = 1212810
Safe sequence is < P0 P3 P4 P1 P2 >
System continues to be in safe state. Request from P1 is granted.
Request from P4 (0,0,2,0)
Request <= Need -> 0020 <= 2233
Request <= Available -> 0020 <= 3321
Allocation = Allocation + Request = 1432 + 0020 = 1452
Need = Need – Request = 2233 – 0020 = 2213
Available = Available – Request = 3321 – 0020 = 3301

Process Allocation Max Work Need


A B C D A B C D A B C D A B C D
P0 2 0 0 1 4 2 1 2 3 3 0 1 2 2 1 1
P1 4 2 2 1 5 2 5 2 1 0 3 1
P2 2 1 0 3 2 3 1 6 0 2 1 3
P3 1 3 1 2 1 4 2 4 0 1 1 2
P4 1 4 3 2 3 6 6 5 2 2 3 3
Operating System

need <= work


P0 --> 2211 <= 3301 ×
P1 --> 1031 <= 3301 ×
P2 -->0213 <= 3301 ×
P3 -->0112 <= 3301 ×
P4 --> 2213 <= 3301 ×
The request from P4 is not granted. The system is not in safe state.
Q3.

Process Allocation Max


A B C D A B C D
P0 0 1 1 2 0 0 1 2
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6
P3 0 6 3 2 0 6 5 2
P4 0 0 1 4 0 6 5 6

Available
A B C D
1 5 2 0

A) What is the content of Need matrix?


B) Is the system in safe state?
C) If a request from process P1 (0,4,2,0) arrives, can it be granted?
Need = Max – Allocation

Process Need
A B C D
P0 0 0 0 0
P1 0 7 5 0
P2 1 0 0 2
P3 0 0 2 0
P4 0 6 4 2
Operating System

need <= work


P0 --> 0000 <= 1520
w = 1520 + 0012 = 1532
P1 --> 0750 <= 1532 ×
P2 --> 1002 <= 1532
w = 1532 + 1354 = 2886
P3 --> 0020 <= 2886
w = 2886 + 0632 = 214118
P4 --> 0642 <= 214118
w = 214118 + 0014 = 2141212
P1 --> 0750 <= 2141212
w = 2141212 + 1000 = 3141212
Request from Process P1 (0,4,2,0)
Request <= Need -> 0420 <= 0750
Request <= Work -> 0420 <= 1520
Work = Work – Request = 1520 – 0420 = 1100
Allocation = Allocation + Request = 1000 + 0420 = 1420
Need = Need – Request = 0750 – 0420 = 0330

Process Allocation Max Work Need


A B C D A B C D A B C D A B C D
P0 0 0 1 2 0 0 1 2 1 1 0 0 0 0 0 0
P1 1 4 2 0 1 7 5 0 0 3 3 0
P2 1 3 5 4 2 3 5 6 1 0 0 2
P3 0 6 3 2 0 6 5 2 0 0 2 0
P4 0 0 1 4 0 6 5 6 0 6 4 2
need <= work
P0 --> 0000 <= 1100
w = 1100 + 0012 = 1112
Operating System

P1 --> 0330 <= 1112 ×


P2 --> 1002 <= 1112
w = 1112 + 1354 = 2466
P3 --> 0020 <= 2466
w = 2466 + 0632 = 21098
P4 --> 0642 <= 21098
w = 21098 + 0014 = 2101012
P1 --> 0750 <= 2101012
w = 2101012 + 1420 = 3141212
Sequence is < P0 P2 P3 P4 P1 >
The safe sequence is same, so the system continues to remain in a safe state.
The request P1 (0,4,2,0) can be granted.
Q5.

Process Allocation Max


A B C A B C
P0 0 1 0 7 3 2
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 0 4 3 3

Available
A B C
3 3 2

Need = Max – Allocation


Operating System

Process Need
A B C
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 3

need <= work


P0 --> 743 <= 332 ×
P1 --> 122 <= 332
w = 332 + 200 = 532
P2 --> 600 <= 532 ×
P3 --> 011 <= 532
w = 532 + 211 = 743
P4 --> 433 <= 743
w = 743 + 000 = 743
P0 --> 743 <= 743
w = 743 + 010 = 753
P2 --> 600 <= 753
w = 753 + 302 = 1055
Safe sequence is < P1 P3 P4 P0 P2 >
The system is in safe state.

You might also like