ulimit CentOS

nproc

It is often necessary to run many processes at the same time.

For example, for load testing

You can see how many processes (nproc) a user is using with the command

ps -lfu $(whoami) | wc -l

For example:

ps -lfu root | wc -l

266

ps -lfu andrei | wc -l

8

The limit values can be found 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

The limit on the number of open files can be increased 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

All the possible options can be found by running

man limits.conf

Or by reading the article limits.conf

Article author: Andrei Olegovich