cat /proc/sys/fs/file-nr
825 0 65536
输出格式: The number of allocated file handles, the number of free file handles, and the maximum number of file handles.
另外一个命令:
lsof | wc -l
有点让我困惑的是,以上两个命令获得的结果总是不相同的;-( 原因如下: 简单来说 file-nr 给出的是 File Descriptors (文件描述符,数据结构,程序用来打开文件所需要的 handle),而 lsof 列出的是 Open Files (文件),包括不是用文件描述符的。例如:当前目录,映射到内存中的 library 文件和可执行的文本文件(脚本?)。通常 lsof 输出要比 file-nr 大。
举个简单的例子:当前系统中Firefox打开的文件数:
lsof -p pid | wc -l
或者
lsof | grep pid | wc -l
再看一下这个进程pid所占用的文件描述符数
ls /proc/pid/fd | wc -l
对比一下就明白了,注:载入到内存的library文件详情可以看/proc/pid/maps。
此外,用sysctl来修改内核参数fs.file-max和用ulimit的区别,花了不少时间研究,讨教了Linux/FreeBSD/Solaris/OpenSolaris老鸟Jockey同学,得到点拨之后终于基本弄清楚其概念和区别了。
优先级(Open File Descriptors): soft limit < hard limit < kernel (NR_OPEN => /proc/sys/fs/nr_open) < 实现最大file descriptor数采用的数据结构所导致的限制
The Linux kernel provides the getrlimit and setrlimit system calls to get and set resource limits per process. Each resource has an associated soft and hard limit. The soft limit is the value that the kernel enforces for the corresponding resource. The hard limit acts as a ceiling for the soft limit: an unprivileged process may only set its soft limit to a value in the range from 0 up to the hard limit, and (irreversibly) lower its hard limit. A privileged process (one with the CAP_SYS_RESOURCE capability) may make arbitrary changes to either limit value.
作为测试环境,尤其是用VMWare guest OS的形式,安装OpenSSH Server, webmin, phpsysinfo等工具可以提高效率。 针对Oracle Enterprise Linux和Red Hat Enterprise Linux的快捷解决方法:
另外OEL和RHEL可以直接安装oracle-validated包来解决安装Oracle数据库和中间件所需要的包依赖和系统配置问题,推荐!
yum install oracle-validated
或者下载后手动安装。
参考:
http://www.debian.org/doc/manuals/reference/ch-kernel.en.html
The Oracle-Validated rpm is available for all users
How Many Open Files?
Related posts: