Report memory of running programs in Linux.
  • C 97.1%
  • Shell 2.9%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-27 10:27:45 +11:00
.clangd Initial commit 2026-10-27 10:27:45 +11:00
.gitignore Initial commit 2026-10-27 10:27:45 +11:00
build.sh Initial commit 2026-10-27 10:27:45 +11:00
main.c Initial commit 2026-10-27 10:27:45 +11:00
README.md Initial commit 2026-10-27 10:27:45 +11:00

memsum

memsum reports memory attributed to each running program on x86-64 Linux. It reads Linux's /proc filesystem and groups processes by their command name.

Only tested on Arch Linux.

Build and run it with:

./build.sh
./memsum
./memsum --name

The default order is total memory from largest to smallest. Use -n or --name to sort program names alphabetically.

Accounting

For each process, memsum reads Pss, Private_Clean, and Private_Dirty from /proc/<pid>/smaps_rollup. PSS divides each shared memory page among the processes that map it, making the summed PSS a more useful estimate of physical memory attributed to programs than summed resident set size (RSS).

The output includes these columns: private memory, shared memory, and their total. Private is the sum of private clean and dirty pages. Shared is calculated as PSS minus private memory, clamped to zero if kernel accounting reports a smaller PSS. Process counts appear beside names when more than one process has that name. Sizes use binary units and one decimal place.

The last line sums the PSS values of all processes successfully read. This is an attribution total: the shared portion is split between processes and is counted once in the PSS sum.

Limits

The kernel can deny access to process details, and processes can start or exit while /proc is being scanned. Such processes are skipped. Running as root usually provides a more complete view.

Linux's comm name is limited to 15 visible characters, so distinct executable names may be grouped together if their names are truncated to the same value. This implementation requires smaps_rollup and PSS support from the kernel; it does not fall back to less accurate RSS accounting. Memory mapped by a service on behalf of another program is attributed to the service that maps it. The scan is a sequence of per-process snapshots, not an atomic system-wide measurement.