Try to read the number of kilobytes in use currently from /proc/self/status and return number of bits in use. Will return negative if error encountered. This gets VmHWM.
integer(int64) function number_of_bits_in_use() result(in_use)
implicit none
! We multiply by 1024 * 8 to convert to bits from kilobytes
in_use = get_status_entry(status_entry = 25) * 1024 * 8
end function number_of_bits_in_use