Resource Limits

From SlackWiki
Jump to navigation Jump to search


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.


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

and ulimit -n should show this:

user@host:~$ ulimit -n

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).


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:

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

user@host:~$ ulimit -n

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