Resident set size of the current process, in bytes, parsed from
VmRSS in /proc/self/status (reported in kB → scaled to
bytes). Returns -1 if the file is unreadable or the field is
absent (non-Linux platforms). Never aborts.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| character(len=256), | private | :: | iomsg | ||||
| integer, | private | :: | ios | ||||
| integer(kind=int64), | private | :: | kb | ||||
| character(len=32), | private | :: | kb_str | ||||
| character(len=256), | private | :: | line | ||||
| integer, | private | :: | unit |
function mem_host_rss_bytes() result(bytes) !! Resident set size of the current process, in bytes, parsed from !! `VmRSS` in `/proc/self/status` (reported in kB → scaled to !! bytes). Returns `-1` if the file is unreadable or the field is !! absent (non-Linux platforms). Never aborts. integer(int64) :: bytes integer :: unit, ios character(len=256) :: line character(len=256) :: iomsg character(len=32) :: kb_str integer(int64) :: kb bytes = -1_int64 open (newunit=unit, file="/proc/self/status", status="old", & action="read", iostat=ios, iomsg=iomsg) if (ios /= 0) return do read (unit, "(a)", iostat=ios, iomsg=iomsg) line if (ios /= 0) exit if (line(1:6) == "VmRSS:") then ! Layout: "VmRSS:\t 12345 kB" — strip the label + "kB". kb_str = adjustl(line(7:)) ! Drop the trailing " kB" unit by reading the leading integer. read (kb_str, *, iostat=ios, iomsg=iomsg) kb if (ios == 0) bytes = kb*BYTES_PER_KIB exit end if end do close (unit) end function mem_host_rss_bytes