Number of Linux file handles

Source: Internet
Author: User
Linux File handle quantity-Linux Enterprise Application-Linux server application information. For details, refer to the following section. When deploying applications in Linux, sometimes the Socket/File: Can't open so many files problem occurs. In fact, Linux has File handle restrictions (like WinXP ?), In addition, the default value is not very high, generally 1024. As a production server, it is very easy to reach this number. Therefore, we need to increase this value.

I probably know that the ulimit command is related. I searched for it on Google. Most of the statements are vague, and I didn't talk about them in a unified way, after reading a lot of articles in two hours, I finally figured out some ulimit-related configuration problems.

We can use ulimit-a to view all the limit values. I only care about the number of file handles.

Open File (-n) 1024

This is the limit.

Here, many articles on ulimit are vague. Is this 1024 a system limitation or a user restriction. In fact, this is due to User restrictions. The complete statement should be the restrictions on the programs to be run by the current user.

1. This restriction is for a single program.
2. The restriction does not change the restriction of the previously running program.
3. The modification to this value will disappear after exiting the current shell.

For example, I first run A program A, then changed the limit to 2048 through ulimit, then run B, then exit shell, then log on, and then run C. Then, only B can open the first 2048 handles.

If we need to change the overall limit value or the program we run is started by the system, what should we do?

One method is to put the ulimit modification command in/etc/profile, but this method is not good.

The correct method should be to modify/etc/security/limits. conf.
There are detailed annotations, such

* Soft nofile 2048
* Hard nofile 32768

You can change the file handle limit to soft 2048 and hard 32768.

Another question is involved here: what is soft limitation and what is hard limitation
The hard limit is the actual limit, while the soft limit is the warnning limit, only the warning
In fact, the ulimit command itself has the hardware and software settings. Adding-H is hard, and adding-S is soft.
Soft restrictions are displayed by default. If they are not added during modification, they are modified together.

The first part of the configuration file is domain, which is set as an asterisk to represent the global. In addition, you can make different restrictions for different users.

Modified, and ulimit will take effect immediately after you log on again. However, new values can be used only when the previously started program is restarted. I use CentOS. It seems that some systems need to be restarted to take effect.

Ulimit is actually a restriction on a single program

What about system restrictions?
Actually, here,/proc/sys/fs/file-max
You can use cat to view the current value and use echo to modify it immediately.

In addition,/proc/sys/fs/file-nr
Read-only, you can see the number of file handles currently used by the entire system

When looking for file handle problems, there is also a very practical program lsof
You can easily see the handles opened by a process.
You can also see which process occupies a file/directory (which of the following issues can be viewed if umount cannot be used)

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.