macOS开发MacOS开发 技术集锦电脑使用技巧 好玩有趣的软件 app 网站

macos解决Too many open files问题

2020-02-09  本文已影响0人  浪里_个郎

直接使用ulimit -n XXX进行修改,发现只能设置比当前值小的值,我们需要另辟蹊径。

尝试过:

$sudolaunchctl limit maxfiles100000500000

$sudoulimit-n100000

但不能对当前command窗口生效。终于,找到了以下有效的方法:

#首先检查当前最大打开文件数的限制

ulimit -n

#新建配置文件

sudo touch /Library/LaunchDaemons/limit.maxfiles.plist

#编辑文件内容如下,其中262144是“soft limit”,524288是"hard limit",有需要可以自行修改

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"

        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

  <dict>

    <key>Label</key>

    <string>limit.maxfiles</string>

    <key>ProgramArguments</key>

    <array>

      <string>launchctl</string>

      <string>limit</string>

      <string>maxfiles</string>

      <string>262144</string>

      <string>524288</string>

    </array>

    <key>RunAtLoad</key>

    <true/>

    <key>ServiceIPC</key>

    <false/>

  </dict>

</plist>

#重启电脑,然后再查看当前最大打开文件数的限制

ulimit -n

看看是不是不一样了?

参考资料:

https://unix.stackexchange.com/questions/108174/how-to-persistently-control-maximum-system-resource-consumption-on-mac

上一篇 下一篇

猜你喜欢

热点阅读