OSX上每个进程打开文件句柄的最大数量(以及如何增加) [英] Maximum number of open filehandles per process on OSX (and how to increase)
问题描述
有人可以帮我理解OSX上打开文件句柄的限制。 ulimit给了我一个答案:
$ $ p $ $ $ $ $ $ $ $打开文件(-n )256
我不能使用 ulimit
改变这一点,但人们建议使用 launchctl
(例如 http://usrinapto.wordpress.com/2010/03/06/mac-os-x-10 -6-max-open-files-too-many-open-files / )
使用这个并不会改变<$ c不过,我的应用程序似乎能够在崩溃之前打开10k个文件,正如<$ c $所报告的那样例如:
$ lsof -p 87599 | c $ lsof
wc
10279 92505 1418903
(在10279和10305之间崩溃,可靠地打开文件)
所以有明显不同的限制。我也看过 FD_SETSIZE
的谈话(在上面的链接中)。
有人可以向我解释什么不同的限制,以及它们是如何设置的?
如果相关,我正在使用SWIG封装一个用于Java的C / C ++库。 / b>
编辑:
我也试过了:
sudo sysctl -w kern.maxfiles = 20000
没有成功。
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ b
没有任何效果。
编辑:
也尝试过
launchctl limit maxfiles 20000 20000
无效。
编辑:
解决方案:
sysctl -w kern.maxfilesperproc = 20000
(via http://krypted.com/mac-os-x/maximum-files-in-mac-os-x/ )
编辑:我写了一个小程序来测试这个(基于 / a>),并发现我可以请求的最大打开文件数是10240: found on http://krypted.com/mac-os-x/maximum- EDIT: I now have a solution, but I'd really apprecite a concise description of what the different limits are, i.e. those set by FD_SIZE, launchtl limit files, sysctl -w kern.maxfilesperproc, ulimit etc.) Can someone help me understand the limits on open filehandles on OSX. ulimit gives me one answer: I can't use Using this doesn't change the limit reported by However, my application seems to able to open 10k files before crashing, as reported by (it crashes somewhere between 10279 and 10305 open files, reliably) So there are clearly different limits coming in to play. I've also seen talk (on the above link) of Can someone explain to me what the different limits are, and how they are set? In case it's relevant, I'm working on wrapping a C/C++ library for use in Java, using SWIG. EDIT:
I've also tried: with no success. Also has no effect. EDIT:
Also tried with no effect. EDIT:
Solution: (via http://krypted.com/mac-os-x/maximum-files-in-mac-os-x/) EDIT: I've written a small program to test this (based on How to increase the limit of "maximum open files" in C on Mac OS X), and found that the max number of open files I can ask for is 10240:
found on http://krypted.com/mac-os-x/maximum-files-in-mac-os-x/:
这篇关于OSX上每个进程打开文件句柄的最大数量(以及如何增加)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ p $ #include< sys /resource.h>
#include< stdio.h>
#include< stdlib.h>
#include< errno.h>
struct rlimit limit;
void setLimit(int l);
void getLimit();
$ b int main(int argc,char * argv [])
{
getLimit();
setLimit(10240);
getLimit();
返回1;
}
void setLimit(int lim)
{
limit.rlim_cur = lim;
limit.rlim_max = lim;
printf(将限制设置为%d,%d \ n,limit.rlim_cur,limit.rlim_max);
if(setrlimit(RLIMIT_NOFILE,& limit)!= 0){
printf(setrlimit()失败,errno =%d \ n,errno);
exit(1);
$ b $ void getLimit()
{
/ *获取最大文件数量。 * /
if(getrlimit(RLIMIT_NOFILE,& limit)!= 0)
{
printf(getrlimit()失败,errno =%d \ n,errno);
exit(1);
}
printf(软限制是%llu \\\
,limit.rlim_cur);
printf(硬限制是%llu \\\
,limit.rlim_max);
sysctl -w kern.maxfilesperproc = 20000
$ ulimit -a
...
open files (-n) 256
ulimit
to change this, but people suggest using launchctl
(e.g. http://usrinapto.wordpress.com/2010/03/06/mac-os-x-10-6-max-open-files-too-many-open-files/)ulimit
, though.lsof
, e.g.:$ lsof -p 87599 | wc
10279 92505 1418903
FD_SETSIZE
.sudo sysctl -w kern.maxfiles=20000
#define FD_SETSIZE 20000
launchctl limit maxfiles 20000 20000
sysctl -w kern.maxfilesperproc=20000
#include <sys/resource.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
struct rlimit limit;
void setLimit( int l );
void getLimit();
int main( int argc, char* argv[] )
{
getLimit();
setLimit(10240);
getLimit();
return 1;
}
void setLimit( int lim )
{
limit.rlim_cur = lim;
limit.rlim_max = lim;
printf( "Setting limit to %d, %d\n", limit.rlim_cur, limit.rlim_max );
if (setrlimit(RLIMIT_NOFILE, &limit) != 0) {
printf("setrlimit() failed with errno=%d\n", errno);
exit(1);
}
}
void getLimit()
{
/* Get max number of files. */
if (getrlimit(RLIMIT_NOFILE, &limit) != 0)
{
printf("getrlimit() failed with errno=%d\n", errno);
exit(1);
}
printf("The soft limit is %llu\n", limit.rlim_cur);
printf("The hard limit is %llu\n", limit.rlim_max);
}
sysctl -w kern.maxfilesperproc=20000