How to solve the problem of Too many open files under Linux

  • 2021-08-31 10:00:24
  • OfStack

The cause is that the process opens more files and communication links than the system limit at some point. The command ulimit-a allows you to see what is the maximum number of handles currently set on the system

core file size          (blocks, -c) 0

data seg size           (kbytes, -d) unlimited

scheduling priority             (-e) 0

file size               (blocks, -f) unlimited

pending signals                 (-i) 31767

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) 31767

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

As you can see, the configuration of open files is 1024, and you can add open files by the following command

ulimit -n 65535

This modification can temporarily increase the number of open files to 65535, but this configuration will be invalid after the system restarts.

Another way is to modify the configuration file of the system. Take Ubuntu as an example, the configuration file defaults to


Add in this configuration file

* soft nofile 65535* hard nofile 6553

If you want to see the number of handles currently open in a process, you can use the following command:

lsof-p Process IDwc-l

In addition, if you host and start a project with supervisor, you will encounter the problem that this configuration will not take effect because supervisor will configure the number of open handles to be 1024 by default.

If you want to view the maximum open files of a process, you can view it through the limits corresponding to the process number of this process

cat/proc/Processes ID/limits

One of the lines is:

Max open files10241024bytes

This line of supervisor managed program is the maximum number of supervisor configuration 1024 by default. In this case, the configuration file of supervisor needs to be changed manually. The modification method is as follows. Take Ubuntu system as an example and find the configuration file of supervisord. conf of supervisor

In the [supervisord] option, add the configuration of the minfds option

[supervisord]minfds=65535; min. avail startup file descriptors; default 1024

After configuration, you need to restart supervisor (take systemctl as an example)

systemctl restart supervisor

It can take effect

After adopting:


Check the number of open files for the corresponding process

Max open files6553565535bytes

The above is how to solve Too many open files under Linux in detail, more information about solving Too many open files under Linux please pay attention to other related articles on this site!

Related articles: