First to popularize a few knowledge:
Everything under Linux is files, including input, network connections, sockets, pipelines, etc.
The most relevant file opening number is the file descriptor (some people like to call the file identifier, the English file descriptor), the essence of the number of open files is the number of file descriptors
Number of open files depends on system type, memory size, int (language keyword, such as C99 int) length (non-negative integer), and system administrator's settings
Maximum file open number is for a process, that is, a process can open the number of file handles is limited, cannot exceed the maximum file open number
The Ulimit command is only valid for the current shell, so when you write a shell script, if you need and can control the maximum number of open files, execute the "ulimit-n File Open" command to perform the following
The file descriptor that is opened in Linux is stored in/proc/pid/fd/, where PID is the process identifier.
In addition to needing attention, it is also important to note that the Ulimit-v Unlimited, the largest available virtual memory (the maximum amount of the VM available to the shell and, on some systems , to its children)
Global settings for the maximum number of file opens:
In CentOS and Ubuntu, Ulimit is a built-in command inside bash, just like if, shift, not a single command, so in Ubuntu you will often encounter someone using sudo ulimit-n 65535 command encountered a hint that the command could not be found (perhaps sudo bug),
Ulimit provides control of the shell or process available resources, including but not limited to the maximum number of open files, the maximum available virtual memory, the maximum number of processes, the socket buffer, etc., it has two kinds of restriction classes hard and soft, respectively, the corresponding parameter switch is-H and-S, The hard limit allows non-root users not to increase (exceed) The set value, soft limit allows non-root users to increase the hard limit, usually the hard value and soft value is set to the same value, the command is ULIMIT-HSN 65535.
However, as mentioned at the beginning of the 5th, Ulimit only valid for the current shell, in order to take effect anywhere, in addition to executing the ULIMIT command is to change the configuration file, that is, change the maximum number of File open global settings, by editing/etc/security/ limits.conf file, add the following two lines to restart the system to take effect . :
* Hard nofile 65535* soft nofile 65535
where "*" means that all users are in effect, after rebooting, executing ulimit-n anywhere will show 65535.
Some commands related to opening number of files and other related commands:
View total file open for current system (Maximum number of opened files): Cat/proc/sys/fs/file-max
View the number of open files for the current process: Lsof-p 16075 | Wc–l
To view the number of file opens on the current port: lsof-i:80 | Wc-l
Before using lsof, it is important to note that lsof is not suitable for viewing a process or port with a high number of connections or a dynamic change in volume
To view files used by a process: Lsof-p 16075
To view files used by a port: lsof-i:80
To view the users and programs that use a file: Fuser-v/bin/bash
Markup a useful classified knowledge of the website: https://en.wikipedia.org/wiki/Category:Unix_file_system_technology
--end--
This article is from "Communication, My Favorites" blog, please make sure to keep this source http://dgd2010.blog.51cto.com/1539422/1676843
Linux Max File Open number use experience detailed