Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
Total Marks:
Obtained Marks:
Operating System
Assignment # 02
Last date of Submission: 28th Dec, 2020
Student Name: Muhammad Haroon
______________________________________________________________________________
Reg. Number: 1880181
______________________________________________________________________________
Submitted to: Ms. Raheela Riaz
_______________________________________________________________________________
OS BSSE-4 SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
Assignment 2 Dead Locks
Q1. Consider the following system snapshot using data structures in the Banker’s algorithm,
with resources A, B, C, and D, and process P0 to P4
Using Banker’s algorithm, answer the following questions.
(i) How many resources of type A, B, C, and D are there?
TOTAL resources of A, B, C, D are.
A=9, B=14, C=10, D=11
Because in available resources are (3, 2, 1, 1)
But in allocation table TOTAL COUNT ARE (6, 12, 9, 10)
Add (3, 2, 1, 1) and (6, 12, 9, 10) = (9, 14, 10, 11)
(ii) What are the contents of the Need matrix?
Need[i, j]=Max[i,j]-Allocation[i,j] therefore content of Need matrix is
Process Need
A B C D
P0 2 0 1 1
P1 0 6 5 0
OS BSSE-4 SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
P2 1 1 0 2
P3 1 0 2 0
P4 1 4 4 4
(iii) Is the system in a safe state? Why? Generate safe sequence?
The system is in a safe state like the processes can be complete in the sequence P0,
P2, P4, P1 and P3.
SEQUENCE P0P2P3P4P1
FOR P0, CHECK.
Process Max Allocation Available Need
A B C D A B C D A B C D A B C D
P0 6 0 1 2 4 1 0 1 3 2 1 1 2 0 1 1
P1 1 7 5 0 1 1 0 0 0 6 5 0
P2 2 3 5 6 1 2 5 4 1 1 0 2
P3 1 6 5 3 0 6 3 3 1 0 2 0
P4 1 6 5 6 0 2 1 2 1 4 4 4
Process Max Allocation Available Need
A B C D A B C D A B C D A B C D
P0 6 0 1 2 3 2 1 1
P1 1 7 5 0 1 1 0 0 7 3 1 2 0 6 5 0
P2 2 3 5 6 1 2 5 4 1 1 0 2
P3 1 6 5 3 0 6 3 3 1 0 2 0
P4 1 6 5 6 0 2 1 2 1 4 4 4
NOW CHWCK FOR P1, BUT P1 IS NOT PERFECT AVAILABLE THERE FOR, THEY MOVE TO
NEXT PROCESS P2
Process Max Allocation Available Need
OS BSSE-4 SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
A B C D A B C D A B C D A B C D
P0 6 0 1 2 3 2 1 1
P1 1 7 5 0 1 1 0 0 7 3 1 2 0 6 5 0
P2 2 3 5 6 8 5 6 6
P3 1 6 5 3 0 6 3 3 1 0 2 0
P4 1 6 5 6 0 2 1 2 1 4 4 4
NOW CHECK FOR PROCESS P3
Process Max Allocation Available Need
A B C D A B C D A B C D A B C D
P0 6 0 1 2 3 2 1 1
P1 1 7 5 0 1 1 0 0 7 3 1 2 0 6 5 0
P2 2 3 5 6 8 5 6 6
P3 1 6 5 3 8 11 9 9
P4 1 6 5 6 0 2 1 2 1 4 4 4
NO TURN TO P4, SEQUENCE MAINTAIN
Process Max Allocation Available Need
A B C D A B C D A B C D A B C D
P0 6 0 1 2 3 2 1 1
P1 1 7 5 0 1 1 0 0 7 3 1 2 0 6 5 0
P2 2 3 5 6 8 5 6 6
P3 1 6 5 3 8 11 9 9
P4 1 6 5 6 8 13 10 11
AND THE LAST ONE IS P1 AND MOVE TO P1 AGAIN
Process Max Allocation Available Need
A B C D A B C D A B C D A B C D
P0 6 0 1 2 3 2 1 1
OS BSSE-4 SZABIST-ISB
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
COMPUTER SCIENCE DEPARTMENT
P1 1 7 5 0 7 3 1 2
P2 2 3 5 6 8 5 6 6
P3 1 6 5 3 8 11 9 9
P4 1 6 5 6 8 13 10 11
TOTAL (9 14 10 11)
Process Max Allocation Available Need
A B C D A B C D A B C D A B C D
P0 6 0 1 2 9 14 10 11
P1 1 7 5 0
P2 2 3 5 6
P3 1 6 5 3
P4 1 6 5 6
(iv) If a request from process P4 arrives for additional resources of (1, 2, 0,
0,), can the Banker’s algorithm grant the request immediately? Show the
new system state.
If a request from process P4 attains for additional resources of (1,2,0,0,), and if such
request is granted so the new system state would be in tabulated form
Process Max Allocation Available Need
A B C D A B C D A B C D A B C D
P0 6 0 1 2 4 1 0 1 2 0 1 1 2 0 1 1
P1 1 7 5 0 1 1 0 0 0 6 5 0
P2 2 3 5 6 1 2 5 4 1 1 0 2
P3 1 6 5 3 0 6 3 3 1 0 2 0
P4 1 6 5 6 1 4 1 2 1 4 4 4
After PO finishes P3 can be assigned. 1020 from released 6012 and also available
2011(Total 80 23) and is a safe sequence.
OS BSSE-4 SZABIST-ISB