Skip to main content

Function Signature

Overview

The InformationMemory() 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

str | None
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:
  1. Reads /proc/meminfo: Uses pathlib.Path to read the contents of the system memory information file
  2. Parses memory values: Extracts four key metrics:
    • MemTotal: Total usable RAM (physical RAM minus reserved bits and kernel binary code)
    • MemFree: Sum of LowFree + HighFree
    • Buffers: Relatively temporary storage for raw disk blocks
    • Cached: In-memory cache for files read from disk
  3. Calculates used memory: Computes actual used memory as:
  4. 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 in memory_info.py:4-32.

See Also