forked from s-aaahill/OS---Sem-IV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
47 lines (38 loc) · 1.25 KB
/
main.cpp
File metadata and controls
47 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <vector>
using namespace std;
// Function to check if the system is in a safe state
bool isSafe(vector<vector<int>> &need, vector<int> &available, vector<vector<int>> &allocation, int n, int m) {
vector<int> work = available;
vector<bool> finish(n, false);
vector<int> safeSequence;
// Safety algorithm
// (Implementation goes here)
return true; // Return true if safe, false otherwise
}
int main() {
int n, m;
cout << "Enter number of processes: ";
cin >> n;
cout << "Enter number of resources: ";
cin >> m;
vector<vector<int>> allocation(n, vector<int>(m));
vector<vector<int>> max(n, vector<int>(m));
vector<int> available(m);
// Input allocation, max, and available matrices
// (Input logic goes here)
// Calculate need matrix
vector<vector<int>> need(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
need[i][j] = max[i][j] - allocation[i][j];
}
}
// Check if the system is in a safe state
if (isSafe(need, available, allocation, n, m)) {
cout << "System is in a safe state." << endl;
} else {
cout << "System is not in a safe state." << endl;
}
return 0;
}