1. 程式人生 > >linux 最大檔案開啟數nofile及nr_open、file-max說明

linux 最大檔案開啟數nofile及nr_open、file-max說明

本文為研究http://www.2cto.com/os/201510/446342.html博文結論

1./etc/security/limits.conf中指定的nofile的值,nofile有上限,不是無窮大。nofile由核心引數nr_open定義的.

“在2.6.25核心之前有個巨集定義,定義了這個值的最大值,為1024*1024,正好是100萬,而在2.6.25核心及其之後,這個值是可以通過/proc/sys/fs/nr_open來設定。”

2.使用cat /proc/sys/fs/nr_open 檢視nr_open值,可通過修改/ect/sysct.conf 修改fs.nr_open值,sysctl -p生效

3.fix_max linux核心定義的最大file handles(檔案控制代碼

數).nr_open定義是單程序最大file-handles,file-handles(即檔案控制代碼)

file-max: The value in file-max denotes the maximum number of file- handles that the Linux kernel will allocate. When you get lots of error messages about running out of file handles, you might want to increase this limit nr_open: This denotes the maximum number of file-handles a process can allocate. Default value is 1024*1024 (1048576) which should be enough for most machines. Actual limit depends on RLIMIT_NOFILE resource limit.
4.file-handles與fd

在UNIX/LINUX中我們接觸更多是file discriptor(FD,即檔案描述符),通過百度搜索,似乎file-handle在windows中是一個類似file discrptor的東東,但是我們討論的是linux,再google一下,我們可以精確到

c語言中這兩個概念的區別,據他們的討論file-handle應該是一個高層的物件,使用fopen,fread等函式來呼叫,而FD是底層的一個物件,可以通過open,read等函式來呼叫。