gpt4 book ai didi

python - python资源中的软硬限制

转载 作者:行者123 更新时间:2023-12-05 02:08:54 25 4
gpt4 key购买 nike

在 python 的 resource 中,softhard 限制之间的实际区别是什么? ?

例如,做之间有什么区别:

import resource
soft_limit,hard_limit=resource.getrlimit(resource.RLIMIT_DATA)

# set soft limit
resource.setrlimit(resource.RLIMIT_DATA, (1024,hard_limit))

# set soft and hard limit
resource.setrlimit(resource.RLIMIT_DATA, (1024,1024))

最后,是的,我已经阅读了关于软限制和硬限制的文档,但仍然不明白实际的区别是什么:

Resources usage can be limited using the setrlimit() function described below. Each resource is controlled by a pair of limits: a soft limit and a hard limit. The soft limit is the current limit, and may be lowered or raised by a process over time. The soft limit can never exceed the hard limit. The hard limit can be lowered to any value greater than the soft limit, but not raised. (Only processes with the effective UID of the super-user can raise a hard limit.)

最佳答案

CPython 的 resource 显然使用了 setrlimit来自 sys/resource。翻看GNU's libc manual ,它对当前(软)和硬限制有这样的说法:

There are two per-process limits associated with a resource:

current limit

The current limit is the value the system will not allow usage to exceed. It is also called the “soft limit” because the process being limited can generally raise the current limit at will.

maximum limit

The maximum limit is the maximum value to which a process is allowed to set its current limit. It is also called the “hard limit” because there is no way for a process to get around it. A process may lower its own maximum limit, but only the superuser may increase a maximum limit.

所以 tl;dr:软是因为一个进程可以增加它的限制,硬是因为它不能,区别在你添加的文档的最后一个带括号的句子中说明:

(Only processes with the effective UID of the super-user can raise a hard limit.)

关于python - python资源中的软硬限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60405540/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com