http://blog.itpub.net/15480802/viewspace-734062
What is an open file
An open file is a regular file, a directory, a block special file, a character special file, an executing text referen CE, a library, a stream or a network file.
What is file descriptor
A file descriptor is a data structure used by a program to get a handle on a file. The most commonly known is:
0 in
1 for standard out
2 for standard error
Relationship between the two
Even if a file is opened, there may be no file descriptor, such as current working directories, memory mapped files and executable text files
Lsof can find out the number of files opened by a process,
[Email protected] ~]# Lsof | grep ' 4448 '
Oracle 4448 Oracle CWD DIR 3,2 4096 1913941/u01/app/oracle/product/10.2.0/db_1/dbs
Oracle 4448 Oracle RTD DIR 3,2 4096 2/
Oracle 4448 Oracle TXT REG 3,2 93300099 1915187/u01/app/oracle/product/10.2.0/db_1/bin/oracle
Oracle 4448 Oracle MEM REG 3,2 95148 2174926/lib/libnsl-2.3.4.so
Oracle 4448 Oracle MEM REG 3,2 106397 2174894/lib/ld-2.3.4.so
Oracle 4448 Oracle MEM REG 3,2 1454546 2501884/lib/tls/libc-2.3.4.so
:
[Email protected] ~]# Lsof | grep ' 4448 ' | Wc-l
42
The following methods are used to query the number of file descriptors used by the process
[Email protected] ~]# ls-l/proc/4448/fd/
Total 18
LR-X------1 Oracle Oinstall 5 15:04 0-/dev/null
LR-X------1 Oracle Oinstall 5 15:04 1-/dev/null
LRWX------1 Oracle Oinstall 5 15:04-/u01/app/oracle/product/10.2.0/db_1/rdbms/audit/ora_4446.aud
LR-X------1 Oracle Oinstall 5 15:04-/dev/zero
LR-X------1 Oracle Oinstall 5 15:04-/dev/zero
:
[Email protected] ~]# Ls-l/proc/4448/fd/| Wc-l
19
Process 4448 opens a total of 42 files, occupying only 19 file descriptors;
To view the settings for a file descriptor
$cat/proc/sys/fs/file-max
65536
--This parameter can be modified dynamically
Calculates the number of file descriptors currently being used
$cat/PROC/SYS/FS/FILE-NR
1380 180 65536
| | |_ Max No. of file descriptors allowed on the system
| |
| |__ Total Free Allocated file descriptors
|
|__ Total Allocated file descriptors
To compute the number of file descriptors currently being used:
1380-180 = 1200
Other useful parameters
Nr_open = Maximum number of OPEN files per process
Nr_file = Total number of files The can is open in the system at any time
File-max = Kernel parameter refers to maximum number of file descriptors allowed per system
File-nr = refers to the number of the current file descriptors used at any moment.
LSOF = Gives The number of open files.
Ulimit–a View the current user's shell limit
If some resources are set too small, the system will not be able to provide services properly
http://space.itpub.net/15480802/viewspace-720722 about the Nofile/nproc test
References Open files/open File descriptors [ID 787780.1]
Linux file descriptor the difference between open file descriptors and open files