prlimit(1) allows to get or set one or more process resource limits for given PID. When a command is given instead of PID, prlimit(1) will run this command with the given resources.
The output is flexible like output from lsblk(8) or findmnt(8). You can define the output columns, use parsable output etc.
See the default output:
$ prlimit --pid $$or redefine the output and ask for max number of open files only:
RESOURCE DESCRIPTION SOFT HARD UNITS
AS address space limit unlimited unlimited bytes
CORE max core file size 0 unlimited blocks
CPU CPU time unlimited unlimited seconds
DATA max data size unlimited unlimited bytes
FSIZE max file size unlimited unlimited blocks
LOCKS max number of file locks held unlimited unlimited
MEMLOCK max locked-in-memory address space 65536 65536 bytes
MSGQUEUE max bytes in POSIX mqueues 819200 819200 bytes
NICE max nice prio allowed to raise 0 0
NOFILE max number of open files 1024 4096
NPROC max number of processes 1024 62809
RSS max resident set size unlimited unlimited pages
RTPRIO max real-time priority 0 0
RTTIME timeout for real-time tasks unlimited unlimited microsecs
SIGPENDING max number of pending signals 62809 62809
STACK max stack size 8388608 unlimited bytes
$ prlimit --nofile --output RESOURCE,SOFT,HARD --pid $$and now let's modify the soft limit of maximal core file size and maximal number of open files:
RESOURCE SOFT HARD
NOFILE 1024 4096
$ prlimit --core=1000000: --nofile=100: --pid $$the notation used for the limits is:
soft:hard specify both limitsand check the result:
soft: specify only the soft limit
:hard specify only the hard limit
value specify both soft and hard limits to the same value
$ prlimit --nofile --core --pid $$and revert the core file soft limit:
RESOURCE DESCRIPTION SOFT HARD UNITS
NOFILE max number of open files 100 1024
CORE max core file size 1000000 unlimited blocks
$ prlimit --core=unlimited: --pid $$Do you want to restrict CPU time for given command (sort(1) in this example):
$ prlimit --core --pid $$
RESOURCE DESCRIPTION SOFT HARD UNITS
CORE max core file size unlimited unlimited blocks
$ prlimit --cpu=10 sort -u hugefileI think prlimit(1) is much better than the shell built-in command ulimit.
Thanks to Davidlohr Bueso who found time to implement prlimit(1) for util-linux 2.21.
-- In memory of Dennis M. Ritchie