CentOS/RHEL: Ulimit And Maximum Number Of Open Files
Sometimes you may want to set limits on some of your system resources(Processes, Files)
But other times, you may want to do the just the opposite - disable those limits or change them to higher limits like I needed to do few days ago.
For some applications/users this is very low and can cause you a lot of problems.
You can check what is the current limit with ulimit using bash shell:
This will show you the hard limit of maximum number of files for your user. you can use -S to check the soft limit.
tcsh: using tcsh you can can check this limit with limit descriptors
if you wish to check the max Open file descriptors for the process your user/application running, use the following command:
To check what is the system limit for number of files descriptors use the following command:
now change the following lines:
save the file and verify the result by using ulimit like we used it in section 1.
If you want to set maximum number of processes use nproc instead of nofile
If you want to set this setting to all users use * instead of specify user name
Now lets change the limit for the entire system:
and put the line:
update the system with::
You can also check the allocated file descriptors by using:
But other times, you may want to do the just the opposite - disable those limits or change them to higher limits like I needed to do few days ago.
1. Check what are the limits
Apparently, RedHat set the default max number of open files for users to 1024 and and not long ago, this was change to 4096.For some applications/users this is very low and can cause you a lot of problems.
You can check what is the current limit with ulimit using bash shell:
1 | ulimit -Hn |
tcsh: using tcsh you can can check this limit with limit descriptors
if you wish to check the max Open file descriptors for the process your user/application running, use the following command:
1 | cat /proc/ [Process ID] /limits |
To check what is the system limit for number of files descriptors use the following command:
1 | cat /proc/sys/fs/file-max |
2. Change the limit
lets start by changing the limit for the user mario:
1 | vi /etc/security/limits .conf |
1 2 | mario soft nofile 4096 mario hard nofile 20480 |
If you want to set maximum number of processes use nproc instead of nofile
If you want to set this setting to all users use * instead of specify user name
Now lets change the limit for the entire system:
1 | vi /etc/sysctl .conf |
1 | fs. file -max = 200500 |
update the system with::
1 | sysctl -p |
3. List number of open files/allocated file handles
To check the number of files opened on your system, use:
1 | lsof | wc -l |
1 | cat /proc/sys/fs/files-nr |
the first field is the number of total allocated files descriptors.
second field is unused file descriptors
and the third field is the maximum file descriptors that can be used