0% found this document useful (0 votes)
7 views2 pages

CS604

The document outlines an assignment for Operating Systems (CS604) where the student, Asjad Subhan, analyzes a system's state using the Banker's Algorithm. It details the steps to determine if the system is in a safe state by calculating the Need matrix, initializing Work and Finish, and finding processes that can proceed. The conclusion is that the system is in a safe state with the safe sequence of processes being P0→P1→P2→P3→P4.

Uploaded by

asjadasjad19
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)
7 views2 pages

CS604

The document outlines an assignment for Operating Systems (CS604) where the student, Asjad Subhan, analyzes a system's state using the Banker's Algorithm. It details the steps to determine if the system is in a safe state by calculating the Need matrix, initializing Work and Finish, and finding processes that can proceed. The conclusion is that the system is in a safe state with the safe sequence of processes being P0→P1→P2→P3→P4.

Uploaded by

asjadasjad19
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/ 2

Operating Systems (CS604) Total marks = 20

Assignment # 02 Name : Asjad


Subhan
Fall 2024

Question Statement 20 marks

Analyze the current state of a system based on the following data, which includes:
a) The available system resources,
b) The resources already allocated to each process,
c) The new resource requests made by each of the five processes (P0, P1, P2, P3, and P4).
Determine whether the system is in a safe state using the Banker’s Algorithm.

Solution:

To determine if the system is in a safe state using the Banker's Algorithm, we need to follow these steps:

Step 1: Calculate the Need Matrix

The Need matrix is calculated as: Need[i][j]=Request[i][j]−Allocation[i][j]

Step 2: Initialize Work and Finish

 Work: Initially, the Available resources vector.


 Finish: Initially set to False for all processes.

Step 3: Find a Process that Can Proceed

Find a process Pi where:

1. Finish[i] = False, and


2. Need[i]≤Work(element-wise comparison).

If such a process is found:

 Allocate its resources back to the Work vector: Work=Work+Allocation[i] = +Allocation[i]


 Set Finish[i] = True.

Repeat until all processes are finished or no more processes can proceed.

Step 4: Check for Safety

If all processes finish successfully (Finish[i] = True for all i), the system is in a safe state. Otherwise, it's unsafe.

Data Input:

1. Available: [3,2,2][3, 2, 2]
2. Allocation:
o P0=[0,1,0]P0 = [0, 1, 0]
o P1=[2,0,0]P1 = [2, 0, 0]
o P2=[3,0,3]P2 = [3, 0, 3]
o P3=[2,1,1]P3 = [2, 1, 1]
o P4=[0,0,2]P4 = [0, 0, 2]
3. Request:
o P0=[0,0,1]P0 = [0, 0, 1]
o P1=[2,0,2]P1 = [2, 0, 2]
o P2=[0,0,0]P2 = [0, 0, 0]
o P3=[1,0,0]P3 = [1, 0, 0]
o P4=[0,0,2]P4 = [0, 0, 2]

Let’s calculate the Need matrix, simulate the allocation process, and check if the system is in a safe state.

The system is in a safe state, and the safe sequence of processes is:

P0→P1→P2→P3→P4 [<_ ]

You might also like