User Tools

Site Tools


linux:files:change_open_files_limit

Linux - Files - Change "Open Files Limit"

If you are getting error “Too many open files (24)” then your application/command/script is hitting max open file limit allowed by linux. You need to increase open file limit as below:

Increase limit

Per-User Limit

Open file /etc/security/limits.conf

Paste following towards end:

/etc/security/limits.conf
*         hard    nofile      500000
*         soft    nofile      500000
root      hard    nofile      500000
root      soft    nofile      500000

NOTE: 500000 is fair number.

  • Once the file is saved, logout and login again.

pam-limits

This is needed to change limits for daemon processes.

Open /etc/pam.d/common-session.

Add following line:

/etc/pam.d/common-session
session required pam_limits.so

System-Wide Limit

Set this higher than user-limit set above.

Open /etc/sysctl.conf, and add the following:

/etc/sysctl.conf
fs.file-max = 2097152

Run:

sysctl -p

NOTE: This will increase the total number of files that can remain open system-wide.


Verify New Limits

Use following command to see max limit of file descriptors:

cat /proc/sys/fs/file-max

returns:

9223372036854775807

Hard Limit

ulimit -Hn

returns:

1048576

Soft Limit

ulimit -Sn

returns:

1024

Check limit for other user

su - www-data -c 'ulimit -aHS' -s '/bin/bash'

NOTE: Just replace www-data by the linux username to check limits for that user.


Check limits of a running process

Find process-id (PID)

ps aux | grep process-name

Check the limit

cat /proc/XXX/limits

NOTE: Suppose, XXX is the PID found earlier.


linux/files/change_open_files_limit.txt · Last modified: 2023/07/17 18:35 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki