How do I get the memory usage?
-
wrote on 13 Jan 2016, 09:51 last edited by ForestPoem
my Function.
fp = fopen("/proc/meminfo", "r");
memory usage=(memory total - memory free )*100
Currently this is in use.
However, this seems to be the wrong way.
How do I get the memory usage? in linux
-
What exactly do you want to have? Bytes used? Percentage used?
What do you try to calculate with this code: (memory total - memory free )*100 ?
memory total - memory free gives you amount of used kBytes. -
To calculate the percentage of used memory do: (used memory * 100) / memory total
-
my Function.
fp = fopen("/proc/meminfo", "r");
memory usage=(memory total - memory free )*100
Currently this is in use.
However, this seems to be the wrong way.
How do I get the memory usage? in linux
wrote on 13 Jan 2016, 10:24 last edited by@ForestPoem I am afraid Qt is not proposing a portable solution for this...but could you please detail why you think reading proc/meminfo is the wrong way ?
Another method on linux is reading the sysinfo struct
-
my Function.
fp = fopen("/proc/meminfo", "r");
memory usage=(memory total - memory free )*100
Currently this is in use.
However, this seems to be the wrong way.
How do I get the memory usage? in linux
wrote on 14 Jan 2016, 02:28 last edited byi'm solved.
((total - free + buffer + cache) / total) * 100 -
i'm solved.
((total - free + buffer + cache) / total) * 100@ForestPoem Are you sure? It should be ((total - free + buffer - cache) / total) * 100
At least cache should not be considered as used memory as it is available for application/system as soon as it is needed. The system just uses unused memory as file cache, but that does not mean that this memory is not available. -
@ForestPoem Are you sure? It should be ((total - free + buffer - cache) / total) * 100
At least cache should not be considered as used memory as it is available for application/system as soon as it is needed. The system just uses unused memory as file cache, but that does not mean that this memory is not available.wrote on 14 Jan 2016, 07:30 last edited by -
Well it depends on what you mean if you say "utilization". From application point of view file cache is free memory.
See here: http://www.logicmonitor.com/blog/2014/07/17/the-right-way-to-monitor-virtual-memory-on-linux/
2/8