[[linux_wiki:file_descriptors]]

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

  • Distro(s): Any

View system wide file descriptor information

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

The three numbers returned:

  • 6144 = used file descriptors
  • 0 = allocated but not used
  • 809542 = system max

Change System FD Limits

Edit /etc/sysctl.conf

fs.file-max = 810542

Example above increases system wide max by 1,000.


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.


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.

  • Increase one of them or
  • Determine what processes is opening so many files and kill it.

See how many open files a user has

lsof -u bill 2>/dev/null | wc -l
  • linux_wiki/file_descriptors.txt
  • Last modified: 2019/05/26 03:50
  • (external edit)