Quickie tutorial: ulimit, soft limits, hard limits, soft stack, hard stack

A quick thing I ran into today using ulimit. Quick, helpful, short. So short maybe it didn’t necessitate such a long blog title.

ulimit sample

ulimit for the impatient

Helpful commands you are likely looking for

Sponsored Links

  • ulimit -S -a view all soft limits
  • ulimit -H -a view all hard limits
  • ulimit -S [option] [number] set a specific soft limit for one variable
    • e.g. ulimit -S -s 8192 set a new soft stacksize limit, “-s” is for stack
  • ulimit -H [option] [number] set a specific hard limit for one variable
    • e.g. ulimit -H -s 8192 set a new hardstacksize limit, “-s” is for stack
  • /etc/security/limits.conf file where you can set soft and hard limits per user or for everyone
    • e.g. Add in the following to /etc/security/limits.conf will set a soft stacksize of 8192 adn a hard stacksize of unlimited for username “user”:

      user soft stack 8192
      user hard stack unlimited

ulimit tutorial in more detail

What is ulimit?

ulimit provides control over resources available to each user via a shell. You can type “ulimit -a” to get a list of all current settings. In parentheses you will see one or two items: the units in measurements (e.g. kbytes, blocks, seconds) as well as a letter option (e.g. -s, -t, -u). The letter option will let you view/edit one particular setting at a time.


What can I set?

Using “ulimit -a” you can see all the values you can set. Using the man page you can get more details about what these are.

See below:

ulimit example screenshot

You can also look in the man page, though I prefer viewing the /etc/security/limits.conf file for more info. Easier to read. See excerpt below:

/etc/security/limits.conf ulimit items

What is “soft” limit vs “hard” limit for ulimit?

  • A hard limit is the maximum allowed to a user, set by the superuser/root. This value is set in the file /etc/security/limits.conf. Think of it as an upper bound or ceiling or roof.
  • A soft limit is the effective value right now for that user. The user can increase the soft limit on their own in times of needing more resources, but cannot set the soft limit higher than the hard limit.

Can a user change default “soft” limits?

Yes, they can do so by putting a “ulimit” command in their shell startup file (typically .bashrc, .bash_profile, .cshrc, .profile, etc.)

e.g. if user wants to change soft limit for stack size to 8192, they put this in their login start up file:

ulimit -S -s 8192

If it is a script they are running (e.g. out of cron), they can also put this statement at the start of their shell script.

How to change the default “soft” limits and “hard” limits for user?

Superuser a.k.a. root can edit the /etc/security/limits.conf file for that user

An example /etc/security/limits.conf file

With all the above bullet points made, here is an example /etc/security/limits.conf file for you to see. Mostly self explanatory on all the options, and you’ll see I changed the default “soft” and “hard” stack for a specific user “byau”

/etc/security/limits.conf file

An example session with ulimit commands

I opted for a screenshot instead of copy/paste because the copy/paste did not properly format (*sigh*). Making the screenshot much easier to read:

ulimit screenshot example


Geek, Linux

4 thoughts on “Quickie tutorial: ulimit, soft limits, hard limits, soft stack, hard stack

  1. In the Limits.conf can the Soft limit be defined as a value greater that the Hard limit? Like below..
    user soft nofile 65536
    user hard nofile 65534

Leave a Comment

Your email address will not be published. Required fields are marked *

Spam protection by WP Captcha-Free