Linux prompts too many open files solution

Source: Internet
Author: User

– Properly configure Linux to open file handle limits and lsof command usage

Today I saw a system error report from the performance test group, the application under the Linux system under pressure will appear "Too Many open files" error and cause the service to stop.

This is the old problem, that is, the need to properly configure Linux can also open the file handle number limit.
Of course, if the application has bugs, misuse of resources is another issue.

Linux most of the resources will be virtual files, as open Network connections will occupy the file handle, Linux default limit is generally 1024, this restriction on the general personal use is not a problem, but for a special application or both in the large concurrent access is not enough.

User level:

Linux limits the number of connected files per logged-on user. You can view the currently valid settings by Ulimit-n. If you want to modify this value, use the Ulimit-n command.

For the increase in the file descriptor, the data recommendation is referred to as a power of 2. If the current file descriptor number is 1024, it can be increased to 2048, if not enough, to 4096, and so on.

System level:

System-level settings are valid for all users. There are two ways to view the maximum file limit of a system

1 Cat/proc/sys/fs/file-max
2 sysctl-a View Results Fs.file-max the number of configurations in this item

If you need to increase the number of configurations, modify the/etc/sysctl.conf file, configure the Fs.file-max property, and add if the property does not exist.
Use Sysctl-p when configuration is complete to notify the system to enable this configuration


1 Cat/proc/sys/fs/file-max
2 sysctl-a


View the number of Fs.file-max this item in the results

If you need to increase the number of configurations, modify the/etc/sysctl.conf file, configure the Fs.file-max property, and add if the property does not exist.
Use Sysctl-p when configuration is complete to notify the system to enable this configuration

If you want to see the specific use of a file handle, you can use the lsof command to give a few examples:

1. View the files that a process (PID) is using

Lsof-p PID

2. Find out who is using a file

Lsof/var/run/sendmail.pid

3. Find the process of listening on port 25

Lsof-i: 25

Oh, the function is still very powerful.

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.