Linux Max File Open number use experience detailed

Source: Internet
Author: User

First to popularize a few knowledge:

    1. Everything under Linux is files, including input, network connections, sockets, pipelines, etc.

    2. 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

    3. 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

    4. 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

    5. 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

    6. 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:

    1. View total file open for current system (Maximum number of opened files): Cat/proc/sys/fs/file-max

    2. View the number of open files for the current process: Lsof-p 16075 | Wc–l

    3. To view the number of file opens on the current port: lsof-i:80 | Wc-l

    4. 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

    5. To view files used by a process: Lsof-p 16075

    6. To view files used by a port: lsof-i:80

    7. To view the users and programs that use a file: Fuser-v/bin/bash

    8. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.