Function Signature
Overview
TheInformationMemory() function reads system memory information from /proc/meminfo and returns a formatted string containing key memory statistics including total memory, free memory, buffers, cached memory, and calculated used memory.
This function parses the /proc/meminfo file to extract essential memory metrics and presents them in a human-readable format with values in kilobytes (kB).
Return Value
Returns a formatted string containing memory statistics, or
None if the memory information cannot be read.The string format is:Implementation Details
The function performs the following operations:- Reads
/proc/meminfo: Usespathlib.Pathto read the contents of the system memory information file - Parses memory values: Extracts four key metrics:
MemTotal: Total usable RAM (physical RAM minus reserved bits and kernel binary code)MemFree: Sum of LowFree + HighFreeBuffers: Relatively temporary storage for raw disk blocksCached: In-memory cache for files read from disk
- Calculates used memory: Computes actual used memory as:
- Returns formatted output: All values are returned in kilobytes (kB)
The function returns
None if the /proc/meminfo file cannot be read or is empty. This typically only occurs on non-Linux systems or in environments where /proc is not mounted.Example Output
Usage Example
Source Code Reference
The implementation can be found inmemory_info.py:4-32.
See Also
- ListDirectory - Find the process with highest memory usage
- Quickstart Guide - Get started with Memory Monitor