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.