RHEL Linux ulimit
Introduction
ulimit is a shell built-in command used to display and set various resource usage limits for the shell.
Among the limits you can set you will find the maximum file size, the maximum core file size, and the maximum resident memory size.
Although the limits do not depend on the shell, the exact syntax depends on which shell you use.
It is recommended to set some of these limits so that, for example, a faulty shell script cannot start an unlimited number of copies of itself, or so that users on the system do not start processes that run forever.
nproc
Often you need to run many processes at once.
For example, for
load testing
You can see how many processes (nproc) a user is running with the command
ps -lfu $(whoami) | wc -l
For example:
ps -lfu root | wc -l
266
ps -lfu andrei | wc -l
8
You can find the limit values by running
ulimit -a
core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 31190 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
You can try to change the limit by editing the file limits.conf
sudo vi /etc/security/limits.conf
#* soft core 0 #* hard rss 10000 #@student hard nproc 20 #@faculty soft nproc 20 #@faculty hard nproc 50 #ftp hard nproc 0 #@student - maxlogins 4 andrei soft nproc 20000 andrei hard nproc 22000 # End of file
If that does not help, edit 20-nproc.conf
sudo vi /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent # accidental fork bombs. # See rhbz #432903 for reasoning. * soft nproc 4096 root soft nproc unlimited andrei soft nproc 10001 andrei hard nproc 11000
Log in to the terminal again
ulimit -a
core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 31190 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 10001 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
nofile
You can increase the limit on the number of open files in a similar way
sudo vi /etc/security/limits.d/20-nproc.conf
# Default limit for number of user's processes to prevent # accidental fork bombs. # See rhbz #432903 for reasoning. * soft nproc 4096 root soft nproc unlimited andrei soft nofile 2048
Log in to the terminal again
ulimit -a
core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 31190 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 10001 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited
You can learn about all the possible options by running
man limits.conf
Or by reading the article limits.conf
Article author: Andrei Olegovich