function::proc_mem_size - Linux


proc_mem_size provides detailed memory statistics for the current process. It displays information about virtual memory, resident set size, shared memory, dirty pages, and more. It is useful for performance monitoring, debugging memory-related issues, and optimizing memory usage in Linux environments.


proc_mem_size [-f <format>] [-t] [-u] [-c <count>]


  • -f : Use a specific output format:
    • text: Human-readable text (default)
    • json: JSON output
    • csv: Comma-separated values
  • -t: Display a timestamp with each output.
  • -u: Display values in human-readable units (e.g., KiB, MiB).
  • -c : Limit the number of measurements before exiting (default: 1).


Print basic memory statistics:


Display in JSON format:

proc_mem_size -f json

Monitor memory usage over time:

while true; do proc_mem_size -f text -t -c 10; sleep 1; done

Extract specific memory value (e.g., RSS):

proc_mem_size | grep "Resident Set Size" | awk '{print $2}'

Common Issues

  • Invalid output format: Ensure you specify a valid format using -f.
  • Missing permission: Running the command without root privileges may result in incomplete or incorrect output.


Combine with other commands:

  • Monitor memory usage during a specific process: ps aux | grep <process-name> | proc_mem_size -f text
  • Analyze memory usage of multiple processes: cat /proc/self/status | proc_mem_size -c 100

Related Commands

  • ps: Display process information
  • vmstat: Report virtual memory statistics
  • top: Display real-time process and system statistics