Differences
This shows you the differences between two versions of the page.
linux_wiki:file_descriptors [2015/03/10 21:18] billdozor created |
linux_wiki:file_descriptors [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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** | ||
- | * Distros: All | ||
- | |||
- | ---- | ||
- | |||
- | ===== System Wide ===== | ||
- | |||
- | **View system wide file descriptor information** | ||
- | <code bash> | ||
- | 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 / | ||
- | <code bash> | ||
- | fs.file-max = 810542 | ||
- | </ | ||
- | Example above increases system wide max by 1,000. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Per User ===== | ||
- | |||
- | **View user file descriptor limits** | ||
- | <code bash> | ||
- | 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 " | ||
- | |||
- | **Change user file descriptor limits** | ||
- | |||
- | Edit / | ||
- | <code bash> | ||
- | #< | ||
- | bill soft | ||
- | bill hard | ||
- | </ | ||
- | Save and reboot. | ||
- | |||
- | ---- | ||
- | |||
- | ===== File Descriptor Errors in Bash ===== | ||
- | |||
- | If you see this error while trying to execute a command in bash: | ||
- | <code 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 | ||
- | <code bash> | ||
- | lsof -u bill 2>/ | ||
- | </ |