How do I get the memory usage?
-
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
-
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
i'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. -
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/