【Linux】命令 - ulimit

Posted by 西维蜀黍 on 2021-08-28, Last Modified on 2022-12-10

Demo

# Get the properties of all the user limits:
$ ulimit -a 

# Get hard limit for the number of simultaneously opened files:
$ ulimit -H -n

# Get soft limit for the number of simultaneously opened files:
$ ulimit -S -n

# Set max per-user process limit:
$ ulimit -u 30

Parameters

-a

Display all resource limits that are available.

-A

Set or display the maximum address space size for the process, in units of 1024 bytes. If the limit is exceeded, storage allocation requests and automatic stack growth will fail. An attempt to set the address space size limit lower than the current usage or to set the soft limit higher than the existing hard limit will fail.

-c

Set or display the core file limit. The core file limit is the maximum size of a dump of memory (in 512-byte blocks) allowed for the process. A value of 0 (zero) prevents file creation. Dump file creation will stop at this limit.

-d

Set or display the data size limit. The data size limit is the maximum size of the break value for the process, in units of 1024 bytes. This resource always has unlimited hard and soft limits.

-f

Set or display the file size limit. The file size limit is the maximum file size (in 512-byte blocks) allowed for the process. A value of 0 (zero) prevents file creation. If the size is exceeded, a SIGXFSZ signal is sent to the process. If the process is blocking, catching, or ignoring SIGXFSZ, continued attempts to increase the size of a file beyond the limit will fail.

-M

Set or display the amount of storage above the 2 gigabyte bar that a process is allowed to have allocated and unhidden, in megabyte increments. An attempt to set the storage size limit lower than the current usage or to set the soft limit higher than the existing hard limit will fail.

The amount of storage that ulimit -M displays does not necessarily reflect the MEMLIMIT setting found in the user’s RACF® OMVS segment. The value displayed will depend on how the user entered the OMVS shell and whether a change of identity was performed.

-n

Set or display the file descriptors limit. The file descriptors limit is the maximum number of open file descriptors allowed for the process. This number is one greater than the maximum value that may be assigned to a newly created descriptor. Any function that attempts to create a new file descriptor beyond the limit will fail. An attempt to set the open file descriptors limit lower than that already used will fail.

-s

Set or display the stack size limit. The stack size limit is the maximum size of the stack for a process, in units of 1024 bytes. The stack is a per-thread resource that has unlimited hard and soft limits.

-t

Set or display the CPU time limit. The CPU time limit is the maximum amount of CPU time (in seconds) allowed for the process. If the limit is exceeded, a SIGXCPU signal is sent to the process and the process is granted a small CPU time extension to allow for signal generation and delivery. If the extension is used up, the process is terminated with a SIGKILL signal. An attempt to set the CPU limit lower than that already used will fail.

Reference