Mem
_mem_read¶
Read a named field from /proc/meminfo and print its value in kB.
Arguments¶
- $1 (string): Field name (e.g. MemTotal, MemAvailable, SwapTotal)
Exit codes¶
- 0: Field found
- 1: /proc/meminfo not readable
Output on stdout¶
- Value in kB
_mem_convert_kb¶
Convert a kB value to the requested unit and print it. With no flag, passes through kB unchanged.
Arguments¶
- $1 (integer): Value in kB
- $2 (string): Optional unit flag: -K/--kb, -M/--mb, -G/--gb
Output on stdout¶
- Converted integer value
sys_mem_total¶
Print total physical RAM.
Arguments¶
- $1 (string): Optional unit flag: -K/--kb (default), -M/--mb, -G/--gb
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- RAM total in the requested unit
sys_mem_available¶
Print available RAM. Uses MemAvailable (kernel 3.14+), which accounts for reclaimable pages and is more useful than MemFree for "can I allocate more?" queries. Falls back to MemFree on older kernels.
Arguments¶
- $1 (string): Optional unit flag
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- Available RAM in the requested unit
sys_mem_used¶
Print used RAM (MemTotal - MemAvailable).
Arguments¶
- $1 (string): Optional unit flag
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- Used RAM in the requested unit
sys_mem_free¶
Print free RAM (MemFree — genuinely unused pages). Note: MemFree is typically much lower than MemAvailable; see sys_mem_available.
Arguments¶
- $1 (string): Optional unit flag
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- Free RAM in the requested unit
sys_mem_percent¶
Print RAM usage as a percentage (used / total * 100).
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- Percentage with one decimal place, e.g. "34.2"
sys_mem¶
Dispatcher for RAM information sub-commands. With no argument, prints a one-line summary.
Arguments¶
- $1 (string): Sub-command: total, available, used, free, percent
- $2 (string): Optional unit flag for numeric sub-commands: -K, -M, -G
Exit codes¶
- 0: Always
Output on stdout¶
- Requested value, or summary line
sys_swap_total¶
Print total swap space.
Arguments¶
- $1 (string): Optional unit flag: -K/--kb (default), -M/--mb, -G/--gb
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- Swap total in the requested unit
sys_swap_used¶
Print used swap space (SwapTotal - SwapFree).
Arguments¶
- $1 (string): Optional unit flag
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- Used swap in the requested unit
sys_swap_free¶
Print free swap space.
Arguments¶
- $1 (string): Optional unit flag
Exit codes¶
- 0: Success
- 1: /proc/meminfo not readable
Output on stdout¶
- Free swap in the requested unit
sys_swap_percent¶
Print swap usage as a percentage (used / total * 100). Returns 0.0 if no swap is configured.
Exit codes¶
- 0: Always
- 1: /proc/meminfo not readable
Output on stdout¶
- Percentage with one decimal place, e.g. "12.5"
sys_swap¶
Dispatcher for swap information sub-commands. With no argument, prints a one-line summary.
Arguments¶
- $1 (string): Sub-command: total, used, free, percent
- $2 (string): Optional unit flag for numeric sub-commands: -K, -M, -G
Exit codes¶
- 0: Always
Output on stdout¶
- Requested value, or summary line