Table of Contents

File Descriptors

General Information

File descriptors (aka file handles) are files that have been opened by processes. There are settings for limiting the amount of files that can be open for the entire system and also per user.

Checklist


System Wide

View system wide file descriptor information

sysctl fs.file-nr
fs.file-nr = 6144	0	809542

The three numbers returned:

Change System FD Limits

Edit /etc/sysctl.conf

fs.file-max = 810542

Example above increases system wide max by 1,000.


Per User

View user file descriptor limits

su - bill
ulimit -Hn
4096

The above asks ulimit to show the hard limit (-H) for the max number of open file descriptors(-n) for user “bill”. 4096 was returned.

Change user file descriptor limits

Edit /etc/security/limits.conf

#<domain> <type> <item>  <value>
bill      soft   nofile  4096
bill      hard   nofile  8192

Save and reboot.


File Descriptor Errors in Bash

If you see this error while trying to execute a command in bash:

-bash: fork: retry: Resource temporarily unavailable

Then you are hitting a file descriptor limit.

To Fix

Either the system wide limit is being reached or the individual user limit is reached.

See how many open files a user has

lsof -u bill 2>/dev/null | wc -l