2012-06-07 08:52:49 +0000 2012-06-07 08:52:49 +0000
202
202
Advertisement

有没有解决OS X 10.7.1系统中 "系统中打开的文件太多 "的错误的方法?

Advertisement

我需要在OS X 10.7.1. 

有什么办法吗?

Advertisement
Advertisement

答案 (10)

234
234
234
2012-06-29 20:23:19 +0000

根据这篇有用的文章(我推荐阅读):

默认情况下,Mac OS X可以打开的最大文件数被设置为12,288,而一个给定进程可以打开的最大文件数为10,240。

你可以通过以下方法来检查:

  • sysctl kern.maxfiles
  • sysctl kern.maxfilesperproc
  • sysctl -w kern.maxfiles=20480

你可以通过以下方法来增加限制(风险自担)。

  • sysctl -w kern.maxfilesperproc=18000 (或您选择的任何数字)
  • sudo (或您选择的任何数字)

要想永久更改,请使用 /etc/sysctl.conf 将您的设置放入 /etc/launchd.conf (您可能需要创建的),就像这样:

kern.maxfiles=20480
kern.maxfilesperproc=18000

注意:在 OS X 10. 10或更低的版本,你可以像limit maxfiles一样在.bashrc中添加设置,它将覆盖你在这里放的任何东西。

同样,从文章中可以看到:

一旦你这样做了,内核本身就会有一个最大的文件数量,但shell可能没有。

命令是:

ulimit -S -n 2048 # or whatever number you choose

如果你想让它在每次打开shell时都运行,你可以把它添加到你的shell配置文件中(.zshrc, &007或其他什么的)。

63
63
63
2017-01-24 14:56:37 +0000

似乎每个版本的OS X的打开文件限制有完全不同的方法!

**对于OS X Sierra*(10.12.X),你需要:

1./Library/LaunchDaemons/limit.maxfiles.plist处创建一个文件,然后粘贴以下内容(随意更改两个数字(分别是软限制和硬限制):

<?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>64000</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

2.2. **更改新文件的所有者:

sudo chown root:wheel /Library/LaunchDaemons/limit.maxfiles.plist

3.加载这些新的设置:

sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist

4.*最后,检查限制是否正确:

launchctl limit maxfiles
34
Advertisement
34
34
2012-06-07 11:09:52 +0000
Advertisement

你需要增加你的ulimit设置–现在OS X上的ulimit很低–默认是256。在你的 ~/.profile 中添加 ulimit -n 4096 或类似的东西,这将在你的本地环境中解决这个问题。运行ulimit -a来检查你当前的级别

要查看系统设置,请运行这个:

launchctl limit maxfiles

在Lion中,每个进程的设置比以前高了很多(10240)。但如果你还在那里打它,那么你可以使用同样的命令将它设置得更高。要使这些改变永久化,你需要在 /etc/launchd.conf 中添加相关的行。

34
34
34
2017-02-18 00:42:52 +0000
10
Advertisement
10
10
2014-09-04 16:19:11 +0000
Advertisement

朋友们,在Mavericks 10.9.4

ulimit -n 2048上可以正常工作。你可能需要启动一个新的登录会话。

5
5
5
2018-11-23 16:59:24 +0000

对于最新的macOS (编写时:10.14.1),你可以使用sudo launchctl limit maxfiles 64000 524288 (默认为256),但它只在当前会话中工作。使用@ninjaPixel https://superuser.com/a/1171028/760235 )的launchctl作业来永久解决。

1
Advertisement
1
1
2017-05-18 02:52:29 +0000
Advertisement
1
1
1
2019-01-25 13:15:52 +0000

经过上面所有的修改,我的java没有做超过10000个文件。解决的办法是这个jvm标志 **-XX:-MaxFDLimit*

0
Advertisement
0
0
2019-05-29 17:55:40 +0000
Advertisement

类似于https://superuser.com/a/1171028/367819

要检查Mac OS X系统上的当前限制,请运行:

launchctl limit maxfiles

最后两列分别是软限制和硬限制。第一个是/Library/LaunchDaunchDaemons/limit.maxfiles.plist中的属性列表(又名plist)文件,该文件包含以下XML配置:

<?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>200000</string>
          <string>200000</string>
        </array>
      <key>RunAtLoad</key>
        <true/>
      <key>ServiceIPC</key>
        <false/>
    </dict>
  </plist>

这将把打开文件限制设置为200000。第二个plist配置文件应该存储在/Library/LaunchDaemons/limit.maxproc.plist中,其内容如下:

<?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.maxproc</string>
      <key>ProgramArguments</key>
        <array>
          <string>launchctl</string>
          <string>limit</string>
          <string>maxproc</string>
          <string>2048</string>
          <string>2048</string>
        </array>
      <key>RunAtLoad</key>
        <true />
      <key>ServiceIPC</key>
        <false />
    </dict>
  </plist>

这两个plist文件必须由root:wheel拥有,并且权限为-rw-r-r-r–r–。这个权限应该是默认的,但你可以通过运行 sudo chmod 644 来确保这些权限到位。虽然上面介绍的步骤会使系统范围内的打开文件限制在重启时被正确设置,但你也可以通过运行 launchctl limit 手动应用这些限制。这时,你可以重启你的电脑,在终端上输入 ulimit -n。如果你的系统配置正确,你应该看到maxfiles已经被设置为200000。


你可以参考这篇文章了解更多细节。

0
0
0
2016-12-14 18:50:26 +0000

我在做chmod -R时遇到了这个问题,所以我通过小的步骤来解决,例如

# for each directory
find . -type d -exec chmod 755 {} \;
Advertisement

相关问题

12
5
13
8
4
Advertisement