What do the two numbers returned by Python's resource.RLIMIT_VMEM (or resource.RLIMIT_AS) mean?

ぐ巨炮叔叔 提交于 2020-01-25 08:01:07

问题


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?)


回答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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!