Resource Limits
Purpose
This page does not attempt to explain the different types of system resource limits or when it is (or is not) appropriate to change them; see man ulimit and [Google] for that discussion.
However, some users run into problems with the linux kernel's default limit settings, so we'll attempt to explain how to modify them to suit special needs.
Overview
The default settings provided by the kernel are sane values for most multi-user machines. Issuing the command ulimit -Hn should show the following:
user@host:~$ ulimit -Hn 1024
and ulimit -n should show this:
user@host:~$ ulimit -n 1024
The first command shows the hard limit set by the kernel, and the second command shows the soft limit set by the user. An unprivileged user can increase the soft limit (up to the hard limit value), and he is also able to lower the hard limit (but then is unable to increase it, as an unprivileged user cannot raise the hard limit at all).
There are some situations which might require a larger hard limit for users, and the obvious "solution" is to add a line in /etc/profile to increase it. However, this will not work, because normal users cannot increase their hard limits (as indicated above).
Solution
To increase the hard limits for users, you will need to create /etc/initscript and place appropriate commands inside it. The easiest way is to copy the file /sbin/initscript.sample to /etc/initscript and edit the copy, but you are certainly free to "roll your own."
Using the following /etc/initscript file:
PATH=/bin:/sbin:/usr/bin:/usr/sbin export PATH # Increase the hardlimit for open files ulimit -Hn 4096 # Execute the program. eval exec "$4"
You should get the following after a reboot:
user@host:~$ ulimit -Hn 4096 user@host:~$ ulimit -n 1024
Notice that the hardlimit is now 4096 (as specified in /etc/initscript), but the softlimit is still 1024. In other words, you will still need to use /etc/profile (or some other shell init file - see below for recommendation) to raise the desired users' softlimits. With some creative scripting, you can be more selective about which users have what limits.
Rather than editing the system /etc/profile, it's recommended to create a custom file in /etc/profile.d and make it executable. This way, you don't have to worry about trying to merge your changes to /etc/profile when doing Slackware upgrades to new versions.
Other Resources
- man initscript
- man ulimit