Linux – Too many open files on Debian

daemondebianfilesystemslinux

I have long running process at Debian. At some point in throw an error:

Too many open files.

Running:

ulimit -a

shows:

open files (-n)
1024

I wish to increase number of open files in 2 times.
After execution

ulimit -n 2048

the limit is active until end of my session, which is not applicable for the task.

How can I permanently increase number of open files?

Best Answer

If your process is started via a script, you can place the call to ulimit in the script just prior to executing the daemon.

If you wish to increase the ulimit for your user, or for all users, you can set limits that are applied via pam_limits on login. These are set in /etc/security/limits.conf. In your case, you could do something like:

*               hard    nofile             2048

Note that "hard" denotes a hard limit - one that cannot be exceeded, and cannot be altered. A soft limit can be altered by a user (e.g. someone without root capabilities), but not beyond the hard limit.

Read the limits.conf for more information on using pam_limits.