Read VmRSS from /proc/ /status. Returns KiB or None.
(pid: int)
| 408 | |
| 409 | |
| 410 | def get_rss_kib(pid: int) -> int | None: |
| 411 | """Read VmRSS from /proc/<pid>/status. Returns KiB or None.""" |
| 412 | try: |
| 413 | status = Path(f"/proc/{pid}/status").read_text() |
| 414 | for line in status.splitlines(): |
| 415 | if line.startswith("VmRSS:"): |
| 416 | # Format: "VmRSS: 12345 kB" |
| 417 | parts = line.split() |
| 418 | return int(parts[1]) |
| 419 | except (FileNotFoundError, ProcessLookupError, IndexError, ValueError): |
| 420 | return None |
| 421 | return None |
| 422 | |
| 423 | |
| 424 | def sample_rss( |