linux open file number too many open files solution
too many open files
The reason for this prompt is that the number of file/socket connections opened by the program exceeds the system settings.
View the maximum number of open files per user
ulimit -a
-
fdipzone@ubuntu:~$ ulimit -a
-
core file size (blocks, -c) 0
-
data seg size (kbytes, -d) unlimited
-
scheduling priority (-e) 20
-
file size (blocks, -f) unlimited
-
pending signals (-i) 16382
-
max locked memory (kbytes, -l) 64
-
max memory size (kbytes, -m) unlimited
-
open files (-n) 1024
-
pipe size (512 bytes, -p) 8
-
POSIX message queues (bytes, -q) 819200
-
real-time priority (-r) 0
-
stack size (kbytes, -s) 8192
-
cpu time (seconds, -t) unlimited
-
max user processes (-u) unlimited
-
virtual memory (kbytes, -v) unlimited
-
file locks (-x) unlimited
Where open files (-n) 1024 indicates that the maximum number of files allowed to open per user is 1024
View the number of files open on the current system
-
lsof | wc -l
-
watch "lsof | wc -l"
View the number of open files for a process
-
lsof -p pid | wc -l
-
lsof -p 1234 | wc -l
Setting the open files numerical method
ulimit -n 2048
-
fdipzone@ubuntu:~$ ulimit -n 2048
-
fdipzone@ubuntu:~$ ulimit -a
-
core file size (blocks, -c) 0
-
data seg size (kbytes, -d) unlimited
-
scheduling priority (-e) 20
-
file size (blocks, -f) unlimited
-
pending signals (-i) 16382
-
max locked memory (kbytes, -l) 64
-
max memory size (kbytes, -m) unlimited
-
open files (-n) 2048
-
pipe size (512 bytes, -p) 8
-
POSIX message queues (bytes, -q) 819200
-
real-time priority (-r) 0
-
stack size (kbytes, -s) 8192
-
cpu time (seconds, -t) unlimited
-
max user processes (-u) unlimited
-
virtual memory (kbytes, -v) unlimited
-
file locks (-x) unlimited
In this way, the maximum number of open files allowed by the current user can be set to 2048, but this setting method will be restored to the default value after reboot.
Permanent Setup Method
-
vim /etc/security/limits.conf
-
At the end of the day.
-
* soft nofile 4096
-
* hard nofile 4096
The first * represents all users and can set up a user as needed, for example
-
fdipzone soft nofile 8192
-
fdipzone hard nofile 8192
It will take effect after the change is cancelled.