How to solve too multiple open files in linux

Source: Internet
Author: User

How to solve too multiple open files in linux


Too program open files

The cause of this prompt is that the number of file/socket connections opened by the program exceeds the system setting value.


View the maximum number of files that a user can open.

Ulimit-

fdipzone@ubuntu:~$ ulimit -acore file size          (blocks, -c) 0data seg size           (kbytes, -d) unlimitedscheduling priority             (-e) 20file size               (blocks, -f) unlimitedpending signals                 (-i) 16382max locked memory       (kbytes, -l) 64max memory size         (kbytes, -m) unlimitedopen files                      (-n) 1024pipe size            (512 bytes, -p) 8POSIX message queues     (bytes, -q) 819200real-time priority              (-r) 0stack size              (kbytes, -s) 8192cpu time               (seconds, -t) unlimitedmax user processes              (-u) unlimitedvirtual memory          (kbytes, -v) unlimitedfile locks                      (-x) unlimited

Among them, open files (-n) 1024 indicates that each user can open up to 1024 files


View the number of files opened by the current system

lsof | wc -lwatch "lsof | wc -l"

View the number of files opened by a process

lsof -p pid | wc -llsof -p 1234 | wc -l

Set the value of open files

Ulimit-n 2048

fdipzone@ubuntu:~$ ulimit -n 2048fdipzone@ubuntu:~$ ulimit -acore file size          (blocks, -c) 0data seg size           (kbytes, -d) unlimitedscheduling priority             (-e) 20file size               (blocks, -f) unlimitedpending signals                 (-i) 16382max locked memory       (kbytes, -l) 64max memory size         (kbytes, -m) unlimitedopen files                      (-n) 2048pipe size            (512 bytes, -p) 8POSIX message queues     (bytes, -q) 819200real-time priority              (-r) 0stack size              (kbytes, -s) 8192cpu time               (seconds, -t) unlimitedmax user processes              (-u) unlimitedvirtual memory          (kbytes, -v) unlimitedfile locks                      (-x) unlimited

In this way, you can set the maximum number of files allowed to be opened by the current user to 2048, but this setting method will be restored to the default value after the restart.


Permanent setting method

Vim/etc/security/limits. conf add * soft nofile 4096 * hard nofile 4096 at the end
* Indicates all users. You can set a user as needed. For example:

fdipzone soft nofile 8192fdipzone hard nofile 8192
After the change, the cancellation will take effect.


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.