Linux ulimit Command Tutorial – POFTUT

Linux ulimit Command Tutorial


Linux kernel provides some configuration about system-related limits and maximums. These are like maximum file handler count, maximum file locks, maximum process count, etc. These limits are used to stay in a safe area and do not bottleneck system performance. But sometimes these limits should be decreased or increased. ulimit is used to change these limits and maximums.

List All Limits

There are different types of limits and maximum values used in Linux configuration. We can list all existing limits with -a option like below.

$ ulimit -a
List All Limits
List All Limits

We can see that some information about limits are provided.

  • The limit name provided which is useful the limit topic
  • Limit metrics are provided what kind of metrics used
  • The limit option provided to set or list limit value
  • Current limit values are provided

List Specific Limit Configuration and Value

We have seen in the previous example that we can access a specific limit configuration with its option. This will only list the given limit. In this example, we will list  file locks with -x .

$ ulimit -x
List Specific Limit
List Specific Limit

limits.conf Configuration File

limits.conf file is used store limit related configuration. It can be accessed from /etc/security/limits.conf . There s also /etc/security/limits.d directory which can hold multiple configurations files.   For more detailed information about limits.conf read the following tutorial.

limits.conf File To Limit Users, Process In Linux With Examples

Set Limit

We can set limits to the given metric by providing the limit value after the limit option. In this example, we will set the core file size unlimited with the following command.

$ ulimit -c unlimited

We  can check new value by listing the limit which is explained previous steps.

Maximum Number Of Open Files Descriptors

A maximum number of open file descriptors are used to limit concurrent open file count. A lot of files open concurrently will hurt disk and system performance. But in some systems like SIEM, higher values may be more suitable. In this example, we set the maximum number of open files descriptors to 10000 . Changing these ulimit values will require root privileges

$ sudo ulimit -n 10000

Maximum Number Of Process For User

The maximum number of processes for users will limit the process count owner by a single user. The default value is 7900. In this example, we will decrease this value to 500.

$ sudo ulimit -n 500

LEARN MORE  Python Subprocess and Popen() with Examples

2 thoughts on “Linux ulimit Command Tutorial”

  1. Nowadays ulimit and /etc/security/limits.conf has become pretty useless with the exception of processes you start in your shell.

    On ulimit I describe why this is the case and how to solve limit issues in Systemd, Upstart or start-stop-daemon based init scripts.

    Reply

Leave a Comment