问题
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:
What is the difference between the first number and the second number?
How should the reported values like
9223372036854775807be 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?)
回答1:
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.
来源:https://stackoverflow.com/questions/59462305/what-do-the-two-numbers-returned-by-pythons-resource-rlimit-vmem-or-resource-r