Note: this is an old post from my previous blog

 

In this post, I’m going to show you how to raise the limit on the number of open files in your system. I assume in this post that you are using CentOS operating system.

List the limits

Apparently, CentOS has a default of 4096 number of open files limit. For some applications, this is simply not enough and you may want to raise this number.
You can check what is the current limit with the ulimit command

This will show you the hard limit of the maximum number of open files for your user. You can also use -S to check the soft limit.

Note: using tcsh you can check this limit with limit descriptors
if you wish to check the max open file descriptors for a specific process, use the following command: 

To check what is the system limit for the number of files descriptors, use the following command:

Change the limit

Let’s change the limit for the user mario. All the limits are configured in /etc/security/limits.conf

Now change the following lines:

save the file and verify the result by using ulimit like we used it in the first section.
Note: If you want to set maximum number of processes use nproc instead of nofile
Note 2: If you want to set this setting to all users use * instead of specify user name

Let’s also change the limit for the entire system. For this we’ll edit /etc/sysctl.conf

Put the following line in the file

Now update the system with the following command

List the number of open files

To check the number of open files on your system, use the lsof command

You can also check the allocated file descriptors by using:

The first field in the output is the number of total allocated files descriptors. The second field is unused file descriptors and finally, the third field is the maximum file descriptors that can be used