How do I get the memory usage?
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
@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
((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.
How, then, would be appropriate?
i want Utilization.
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/