Posted By: John Meagher
When running my application I sometimes get an error about
too many files open.
ulimit -a reports that the limit is 1024. How do I increase the limit above 1024?
ulimit -n 2048 results in a permission error.
You could always try doing a
ulimit -n 2048. This will only reset the limit for your current shell and the number you specify must not exceed the hard limit
Each operating system has a different hard limit setup in a configuration file. For instance, the hard open file limit on Solaris can be set on boot from /etc/system.
set rlim_fd_max = 166384 set rlim_fd_cur = 8192
On OS X, this same data must be set in /etc/sysctl.conf.
Under Linux, these settings are often in /etc/security/limits.conf.
There are two kinds of limits:
- soft limits are simply the currently enforced limits
- hard limits mark the maximum value which cannot be exceeded by setting a soft limit
Soft limits could be set by any user while hard limits are changeable only by root.
Limits are a property of a process. They are inherited when a child process is created so system-wide limits should be set during the system initialization in init scripts and user limits should be set during user login for example by using pam_limits.
There are often defaults set when the machine boots. So, even though you may reset your ulimit in an individual shell, you may find that it resets back to the previous value on reboot. You may want to grep your boot scripts for the existence ulimit commands if you want to change the default.