Skip to content

ulimit Linux command

The Linux ulimit command allows users to set various resource limits for processes, such as maximum file size, CPU time, and the number of open files. By using ulimit, administrators can control and adjust resource allocations to prevent system overload and ensure efficient performance. This command is particularly useful in multi-user environments where system resources need to be managed effectively to avoid conflicts and bottlenecks. With ulimit, users can tailor resource limits to suit specific needs and optimize system utilization for improved stability and performance.

ulimit Syntax:

Terminal window
ulimit [options] [parameters]

Options:

OptionDescription
-aDisplay all current limits
-cSet the core file size limit
-dSet the data segment size limit
-fSet the file size limit
-lSet the maximum size that can be locked in memory
-mSet the physical memory size limit
-nSet the maximum number of open file descriptors
-qSet the maximum number of bytes in POSIX message queues
-rSet the real-time scheduling priority
-sSet the stack size limit
-tSet the CPU time limit
-uSet the maximum user processes limit
-vSet the virtual memory size limit
-xSet the maximum number of file locks

Parameters:

ParameterDescription
limitsSpecify the particular limit to set or display
soft_limitSpecify the soft limit for a particular resource
hard_limitSpecify the hard limit for a particular resource

ulimit bash Examples:

Set soft limit for maximum number of open file descriptors

Terminal window
ulimit -Sn 1000

This command sets the soft limit for the maximum number of open file descriptors to 1000.

Set hard limit for maximum number of processes

Terminal window
ulimit -Hu 500

Sets the hard limit for the maximum number of processes to 500.

Display current soft limits for resources

Terminal window
ulimit -aS

Displays all current soft limits for the available resources.

Set soft limit for maximum stack size

Terminal window
ulimit -Ss 8192

Sets the soft limit for the maximum stack size to 8192 KB.

Remove limits on maximum number of open file descriptors

Terminal window
ulimit -n unlimited

Removes any previous limits on the maximum number of open file descriptors.

Set hard limit for maximum size of core files

Terminal window
ulimit -Hc 0

Sets the hard limit for the maximum size of core files to 0 KB, preventing core files from being created.

ulimit Command Help Center:

How do I use ulimit in Linux?

To use the ulimit command in Linux, execute the following command:

Terminal window
ulimit --option <value>

What is the purpose of the ulimit command in Linux?

The ulimit command is used to set or display resource limits for processes running in the current shell session.

How can I view the current ulimit settings in Linux?

To view the current ulimit settings, run the following command:

Terminal window
ulimit -a

How do I set the maximum number of open file descriptors using ulimit in Linux?

To set the maximum number of open file descriptors, use the following command:

Terminal window
ulimit -n 10000

How do I set the maximum stack size using ulimit in Linux?

To set the maximum stack size, use the ulimit command with the -s option followed by the desired value. For example:

Terminal window
ulimit -s 8192

How can I set both soft and hard limits using ulimit in Linux?

To set both soft and hard limits, use the ulimit command with the -S and -H options, respectively. For example:

Terminal window
ulimit -S -n 10000
ulimit -H -n 20000

How do I set a time limit for process execution using ulimit in Linux?

You can set a time limit for process execution using the ulimit command with the -t option followed by the time limit in seconds. For example:

Terminal window
ulimit -t 300

How can I remove a specific limit set by ulimit in Linux?

To remove a specific limit set by ulimit, use the command with the - option and provide the keyword unlimited. For example, to remove a limit on stack size:

Terminal window
ulimit -s unlimited

Applications of the ulimit command

  • Limiting the number of open files
  • Limiting the size of core files
  • Limiting the maximum size of virtual memory
  • Limiting the maximum size of locked memory
  • Limiting the maximum number of processes
  • Limiting the maximum number of threads
  • Limiting the maximum size of stack
  • Limiting the maximum size of data segment