getrlimit的单位是什么?

问题描述

请帮助您了解getrlimit的单位。我想它是字节,但仍然是一个巨大的价值。

>>> import resource
>>> soft,hard = resource.getrlimit(resource.RLIMIT_AS)
>>> soft
9223372036854775807
>>> hard
9223372036854775807

解决方法

rlim_t通常为unsigned integer类型,在64位计算机上,最大/无限地址空间为(2 ^ 64)-1,但是您看到的最大限制为9223372036854775807在您的机器上。在CentOS / Ubuntu机器上,我看到RLIM_INFINITY设置为-1,在MacOS上,它将9223372036854775807设置为代表无限限制的常量。

resource.RLIM_INFINITY :常量,用于表示无限资源的限制。

在CentOS计算机上:

[root ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root ~]# ulimit -a | grep virtual
virtual memory          (kbytes,-v) unlimited
[root ~]# python
Python 2.7.5 (default,Oct 30 2018,23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help","copyright","credits" or "license" for more information.
>>> import resource
>>> resource.RLIM_INFINITY
-1
>>> soft,hard = resource.getrlimit(resource.RLIMIT_AS)
>>> soft
-1
>>> hard
-1
>>>