Skip to content

ulimit MacOS command

The ulimit command on MacOS allows users to set or display resource limits for processes. These limits can include restrictions on memory, open files, stack size, and more. By using ulimit, users can control how much resources a process can use, ensuring system stability and preventing resource exhaustion. The ulimit command is used in the terminal and provides a range of options for managing resource limits. This command can be particularly useful for system administrators and developers who need to fine-tune resource allocations for optimal performance.

ulimit Syntax:

Terminal window
ulimit [option] [parameter]

Options:

OptionDescription
-cSet or display the core file size limit.
-dSet or display the process data limit.
-fSet or display the file size limit.
-lSet or display the maximum locked memory limit.
-mSet or display the physical memory limit.
-nSet or display the file descriptor limit.
-qSet or display the POSIX message queue limit.
-rSet or display the real-time priority limit.
-sSet or display the stack size limit.
-tSet or display the CPU time limit.
-uSet or display the user processes limit.
-vSet or display the virtual memory limit.
-xSet or display the file locks limit.

Parameters:

ParameterDescription
limitThe specific resource limit to be set or displayed.

ulimit bash Examples:

Set soft limit for the number of open files

Terminal window
ulimit -S -n 1000

This command sets the soft limit for the number of open files to 1000.

Display current limits

Terminal window
ulimit -a

This command displays the current resource limits for the shell.

Set the maximum size for a core file

Terminal window
ulimit -c unlimited

This command sets the maximum size for a core file to unlimited.

Set the stack size limit

Terminal window
ulimit -s 8192

This command sets the stack size limit to 8192 KB.

Set the maximum number of processes

Terminal window
ulimit -u 500

This command sets the maximum number of processes to 500.

Set the maximum virtual memory size

Terminal window
ulimit -v 2097152

This command sets the maximum virtual memory size to 2097152 KB.

How do I check the current limits in MacOS using ulimit?

To check the current limits in MacOS using ulimit, run the following command:

Terminal window
ulimit -a

How do I set the maximum number of open files using ulimit in MacOS?

To set the maximum number of open files using ulimit in MacOS, use the following command:

Terminal window
ulimit -n <value>

How do I set the stack size limit with ulimit command in MacOS?

To set the stack size limit using ulimit command in MacOS, execute the following command:

Terminal window
ulimit -s <value>

How do I set the maximum core file size limit with ulimit in MacOS?

To set the maximum core file size limit using ulimit in MacOS, use the following command:

Terminal window
ulimit -c <value>

How do I set the maximum user processes limit using ulimit in MacOS?

To set the maximum user processes limit using ulimit in MacOS, run the following command:

Terminal window
ulimit -u <value>

How do I set the maximum virtual memory size limit with ulimit in MacOS?

To set the maximum virtual memory size limit using ulimit in MacOS, use the following command:

Terminal window
ulimit -v <value>

How do I set the maximum CPU time in seconds using ulimit in MacOS?

To set the maximum CPU time in seconds using ulimit in MacOS, execute the following command:

Terminal window
ulimit -t <value>

How do I remove a specific limit with ulimit in MacOS?

To remove a specific limit using ulimit in MacOS, run the following command with the desired option:

Terminal window
ulimit -<option> unlimited

Applications of the ulimit command

  • Limiting the amount of CPU time
  • Limiting the size of core files
  • Limiting the size of virtual memory
  • Limiting the size of stack size
  • Limiting the number of open files
  • Limiting the number of processes
  • Limiting the number of threads