-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryInfo.cpp
More file actions
50 lines (38 loc) · 1.13 KB
/
MemoryInfo.cpp
File metadata and controls
50 lines (38 loc) · 1.13 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
48
49
#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
using namespace std;
int main() {
int Memory; // Variable to store available memory
int choice;
cout<<"1. UserMode\n";
cout<<"2. KernalMode\n";
cout<<"Enter Choice: ";
cin>>choice;
if(choice!=2)
{
cout<<"Memory Only Fetch From KernalMode You Select UserMode\n";
}
else
{
// Get the shared memory segment created by the parent process
int shmid = shmget((key_t)8749, sizeof(int), IPC_CREAT | 0666);
if (shmid == -1) {
perror("Failed!");
return 1;
}
// Attach the shared memory segment
int* SharedData = (int*)shmat(shmid, NULL, 0);
if (SharedData == (int*)(-1)) {
perror("Failed!");
return 1;
}
// Store the available memory in the shared memory segment
// *SharedData = Memory;
// Display the available memory from the shared memory segment
cout << "Available Memory: " << *SharedData << " MB" << endl;
cout << "Available Disk Space: " << 500<< " MB" << endl;
cout << "Available Cores: " << 2<< " MB" << endl;
}
return 0;
}