4

在 macOS 10.7 上,使用 bash

第一次调用 ulimit -n 成功,第二次失败。

a:$ ulimit -n 
2560
a:$ ulimit -n 5000
a:$ ulimit -n 
5000
a:$ ulimit -n 6000
bash: ulimit: open files: cannot modify limit: Operation not permitted

但是,如果我在一个新的 shell(或另一个 shell)中尝试 ulimit -n 6000,它会成功:

a:$ ulimit -n 
2560
a:$ ulimit -n 6000
a:$ ulimit -n 
6000

这是为什么?

4

1 回答 1

4

从 bash 手册页:

硬限制一旦设置就不能增加;软限制可以增加到硬限制的值。如果既没有指定 -H 也没有指定 -S,则同时设置软限制和硬限制。

大多数现代 *NIX 实际上不再使用ulimit了。我猜OS X没有设置ulimit hard max,所以你的第一个调用设置了soft max和hard max,所以你的第二个调用每次都失败。没有 [limit] 参数的第一个调用可能是打印软最大值。

于 2011-07-11T21:28:31.850 回答