I’ve known for a long time about ulimit
to modify a shell’s resource limits (and of course nice
and renice
to change a process’s priority). Incredibly, in a few decades I never knew or heard about prlimit
, which allows you to set limits for a command or, more importantly, update resource limits for a running process.
# Need more file descriptors? prlimit --nofile=2048 my-file-eater # Oops, ran out mid-execution, let's raise it prlimit --nofile=4096 $(pgrep my-file-eater) # What are the limits right now? prlimit RESOURCE DESCRIPTION SOFT HARD UNITS AS address space limit unlimited unlimited bytes CORE max core file size 0 unlimited bytes CPU CPU time unlimited unlimited seconds DATA max data size unlimited unlimited bytes FSIZE max file size unlimited unlimited bytes LOCKS max number of file locks held unlimited unlimited locks MEMLOCK max locked-in-memory address space 67108864 67108864 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 1048576 files NPROC max number of processes 62610 62610 processes RSS max resident set size unlimited unlimited bytes RTPRIO max real-time priority 0 0 RTTIME timeout for real-time tasks unlimited unlimited microsecs SIGPENDING max number of pending signals 62610 62610 signals STACK max stack size 8388608 unlimited bytes