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?
There is also a "total max" of open files set in the kernel, you can check the current setting with:
And set a new value with:
If you want to keep the config between reboots add
to
To check current max file usage:
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: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 usingpam_limits
.Be aware that if you run your process by start-stop-daemon setting ulimits in /etc/security/limits.conf doesn't work. If you for example want to raise open file limit for tomcat to 20000 you need to add these to lines to
/etc/default/tomcat
:I encountered this problem on debian 6.0.4 For other process the answers given should help.
As others have said you can apply specific limits per user or group in /etc/security/limits.conf.
Note: ulimit -n shows the soft limit.
will show you the hard limit.
This makes ulimit -a and ulimit -n output quite confusing if for example, you were raising the number of files from 1024 to 4096, as you would expect to see the hard limit output, but you're still seeing 1024 which is the soft limit.
Also, remember that these limits are enforced per login, so re-login in a new shell and check your changes , don't expect them to be propagated to existing logins.
It depends on how you start your long-running process. If it's started at boot time (via /etc/rcX.d/* scripts) then you must put a ulimit call in your startup script as the default limit is set by the kernel and it's not tunable without recompiling it.
Using
/etc/security/limits.conf
could work if you usecron
to start it for example with a entry like this:That should work because /etc/pam.d/cron enables pam_limits.so.
You can add this in /etc/security/limits.conf
save then reboot.
A very nice command is
ulimit -n
but there is a problem with too many connection and too many open files: