Documentation Index
Fetch the complete documentation index at: https://mintlify.com/leonardo02lobo/Memory-Monitor/llms.txt
Use this file to discover all available pages before exploring further.
Function Signature
Overview
TheListDirectory() function scans all running processes on the system to identify the process consuming the most physical memory (VmRSS). It returns a list containing a formatted description string and the process ID (PID) as a string of the memory-intensive process.
Despite its name, this function analyzes process memory usage rather than listing directory contents. It operates by scanning the
/proc filesystem to examine each running process’s memory statistics.Return Value
How It Works
Process Discovery
- Scans
/procdirectory: Lists all entries in/proc - Filters for PIDs: Identifies numeric directories (each represents a running process)
- Iterates through processes: Examines each process’s status file
Memory Analysis
For each process, the function:- Opens
/proc/{pid}/status: Reads the process status file - Extracts process name: Parses the
Name:field - Reads VmRSS value: Extracts the
VmRSS:field (Resident Set Size) - Tracks maximum: Keeps track of the process with the highest VmRSS
VmRSS (Resident Set Size) represents the portion of memory occupied by a process that is held in RAM. This is “real” physical memory usage, excluding swapped-out memory pages.
Error Handling
The function gracefully handles two common exceptions:- FileNotFoundError: Process terminated between directory listing and status file read
- PermissionError: Insufficient permissions to read certain process information (common for system processes)
Example Output
Usage Example
Source Code Reference
The implementation can be found inprocess_analyzer.py:4-27.
The function returns a list (not a tuple) with the second element being a string representation of the PID. To use the PID as an integer, convert it:
int(pid).Technical Notes
VmRSS vs Other Memory Metrics
- VmRSS (Resident Set Size): Physical memory actually used (what this function reports)
- VmSize: Total virtual memory allocated (can be larger than physical RAM)
- VmData: Size of data segment
- VmStk: Size of stack
Permissions
Some process information may not be accessible without elevated privileges. The function handles this gracefully by skipping processes it cannot read.See Also
- InformationMemory - Get overall system memory statistics
- Quickstart Guide - Get started with Memory Monitor