Operating System and System
Operating System and System
PROJECT REPORT(15B17CI472)
Step 2:
Present inputs obtained to the user to verify if required
Step 3:
Identify if there are any sinks in the given graph and reduce such nodes. Update the
process state vector appropriately.
Step 4:
Calculate current resource vector by releasing the resources previously held by the
sinks.
Step 5:
Check if there exists a connected node on the remaining graph.
If yes,
Loop through all processes
check if we can allocate the requested resources to the process.
If yes,
Allow the process to finish and release the previously held resource to the
current resource vector.
Else
Go back to step 5
End of loop – Graph is not completely reducible, so the system Is in a
deadlock state. Print the
irreducible processes from the process state vector.
Exit
Else
Graph is completely reduced and Is deadlock free.
Exit
EXAMPLE GRAPHS
Example#1
No of processes: 3
No of resources: 3
Resources allocated matrix: 1 0 0
0 1 0
0 0 1
Example#2
No of processes: 3
No of resources: 3
Resources allocated matrix: 0 2 0
1 0 1
0 1 0
Project objectives:
This problem of having deadlock in real life can be more easily detected with
the help of resource allocation graph. A resource allocation graphs shows
which resource is held by which process and which process is
waiting for a resource of a specific kind. It is amazing and straight –
forward tool to outline how interacting processes can deadlock.
Therefore, resource allocation graph describe what the condition of
the system as far as process and resources are concern like what
number of resources are allocated and what is the request of each
process.
So, resource allocation graph is explained to us what is the state of
the system in terms of processes and resources.
running code
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
class ResourceAllocationGraph {
private:
int numProcesses;
int numResources;
vector<vector<int>> graph;
public:
ResourceAllocationGraph(int processes, int resources)
: numProcesses(processes), numResources(resources) {
graph.resize(numProcesses,
vector<int>(numResources, 0));
}
bool isDeadlocked() {
vector<int> inDegree(numProcesses, 0);
vector<int> work(numResources, 0);
vector<bool> visited(numProcesses, false);
// Calculate in-degree for each process
for (int i = 0; i < numProcesses; ++i) {
for (int j = 0; j < numResources; ++j) {
inDegree[i] += graph[i][j];
work[j] += graph[i][j];
}
}
while (!q.empty()) {
int process = q.front();
q.pop();
int main() {
// Example usage
ResourceAllocationGraph rag(4, 3);
return 0;
}
SCREENSHOTS
Output