The default open file limit per process is 1024 on – say – Linux. For certain daemons this is not enough. Thus, the question: How to change the open file limit for a specific user?
How to configure the process open file limit of a user
limitopen filesprocessulimit
Best Answer
On Linux you can configure it via
limits.conf
, e.g. via(which sets both the hard and soft limit for processes started under the user debian-transmission to 8192)
You can verify the change via:
If a daemon is already running, it has to be restarted such that the new limit is picked up. In case the daemon is manually started from a user session, the user has to re-login to get the new limit.
Alternatively, you can also specify additional limits directly in
/etc/security/limits.conf
, of course - but I prefer the.d
directory approach for better maintainability.For enforcing different soft/hard limits use two entries, e.g.
(rationale behind this: the soft value is set after the user logs in but a users process is allowed to increases the limit up to the hard limit)
The
limits.conf
/limits.d
configuration is used bypam_limits.so
, which is enabled by default on current Linux distributions.Related
There is also a system-wide limit on Linux,
/proc/sys/fs/file-max
:For example the default on Ubuntu 10.04:
The pseudo file
/proc/sys/fs/file-nr
provides more information, e.g.Thus, on the one hand, you also may have to adjust system-wide
file-max
limit, in case its is very small and/or the system is already very loaded. On the other hand, just increasingfile-max
is not sufficient, because it does not influence the soft/hard limits enforced by the pam_limits mechanism.To change
file-max
on the command line (no reboot necessary):For permanent changes add
fs.file-max=786046
to/etc/sysctl.conf
or/etc/sysctl.d
.The upper limit on
fs.file-max
is recorded infs.nr_open
. For example, (again) on Ubuntu 10.04:(which is 1024*1024)
This sysctl is also configurable.