1

Python's resource module allows getting and setting various system resource usage information. In particular, the amount of memory used by a process is available via resource.RLIMIT_VMEM (or, on some systems, resource.RLIMIT_AS as per this StackOverflow answer).

When I run the following Python code (using Python 3.7) to print the memory usage, I see a tuple with two values:

import resource
print(resource.getrlimit(resource.RLIMIT_AS))

On Ubuntu 18.04, it prints (-1, -1) (which I interpret to mean, both values are infinite).

On Mac OS X 10.4, it prints (9223372036854775807, 9223372036854775807) (which is approximately an exabyte worth of bytes).

I have two questions about this output:

  1. What is the difference between the first number and the second number?

  2. How should the reported values like 9223372036854775807 be interpreted - are they numbers of bytes? (Is a very large value just a way of setting a memory limit that is so large it will never be reached?)

charlesreid1
  • 4,360
  • 4
  • 30
  • 52

1 Answers1

2

The two values correspond to rlim_cur (the "soft limit") and rlim_max (the "hard limit") from the getrlimit system call. This is documented in the library documentation for the resource module.

The value -1 corresponds to the resource.RLIM_INFINITY constant, which means there is no set limit.

The units for RLIMIT_AS are defined as bytes, documented here:

resource.RLIMIT_AS The maximum area (in bytes) of address space which may be taken by the process.

You can find further Linux-specific information about the meaning of these values on the getrlimit(2) man page.

Matt Zimmerman
  • 529
  • 5
  • 10