I am working on a Nvidia Jetson TX2 device that runs Ubuntu os. I want to build tensorflow c++ api and I need about 14GB memory available space. Is there some linux commands to check my available memory?
Asked
Active
Viewed 243 times
0
-
There are many: `free, top, htop, cat /proc/meminfo, vmstat`. If you want GPU information you should use `nvidia-smi`. Sadly this question is not a real Stack Overflow questions and should be directed at [unix.se] or similar. – kvantour Aug 25 '21 at 06:23
1 Answers
0
Disk Space
To get the free disk space memory in c++17 you could use the following way:
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::space_info tmp = fs::space("/tmp");
std::cout << "Free space: " << tmp.free << '\n'
<< "Available space: " << tmp.available << '\n';
}
Memory
These both give information regarding memory in linux:
$ cat /proc/meminfo
OR
$ less /proc/meminfo
And then you could use grep
to filter out the information that you need:
$ grep MemTotal /proc/meminfo
Or you could use c++
and the following function to get the total size (this is specific to linux though):
#include <unistd.h>
unsigned long long getTotalSystemMemory()
{
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
}

Renis1235
- 4,116
- 3
- 15
- 27
-
In the first case, what is the rows that I am interested to get memory free disk? Second program, I compiled and run, it returns me a number, this is in kb or mb? – Fredi Aug 25 '21 at 07:14
-
I thought you meant memory and not disk space, check the updated answer. – Renis1235 Aug 25 '21 at 08:08
-
I tried your c++ program for free disk space, I got the next error: filesystem:No such file or directory – Fredi Aug 25 '21 at 09:08
-
Try another directory such as `fs::space("/");` or `fs::space("/home");` and so on – Renis1235 Aug 25 '21 at 09:23
-
-
Then you are not using c++17 and above, can you use another version of c++? – Renis1235 Aug 25 '21 at 10:41