While ulimit
can be used to determine how many files are allowed to be open per process you may want to find the culprit.
@itsadok @Tyler Collier @gaoithe in comments to other answers highlight that sorting and counting which process has the most files open is the best thing to do here:
sudo lsof | head -1 | awk '{ print "COUNT " $2 " " $1; }' && sudo lsof +c 0 | awk '{ print $2 " " $1; }' | sort -rn | uniq -c | sort -rn | head -20
Above command:
- Gives output a header
lsof
gives list of open files
+c 0
option instructs lsof
to print full command
awk '{ print $2 " " $1; }'
prints PID and COMMAND column in results
sort -rn
sorts results so identical entries are next to each other (needed for uniq -c
to work properly)
uniq -c
counts files open by PID/command
sort -rn
sorts results by count
head -20
shows top 20 files open by PID/command
Note: This will count includes "files" that don't count towards limits
You may want to investigate even further by looking at limits for a PID, # of files open for a specific PID, and limit lsof
to only count files that count towards limit - see https://serverfault.com/a/964752/152562.
ulimit
?