Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When running tail -f filename, I got the following message:

tail: inotify cannot be used, reverting to polling: Too many open files

Is that a potential problem?

How do I diagnose what's responsible for all the open files? I have a list of suspect processes, but if they don't turn out to be the culprits, instructions that don't rely on knowing which process to check would be useful.

share|improve this question
1  
Have you increased the number of file descriptors available via ulimit? –  Ignacio Vazquez-Abrams Aug 28 '12 at 3:09
    
@IgnacioVazquez-Abrams That may be helpful to other users, but to me it'd feel like treating the symptom rather than the disease. –  Andrew Grimm Aug 28 '12 at 3:13
    
While you're not wrong, sometimes apps have legitimate reasons for having many files open. –  Ignacio Vazquez-Abrams Aug 28 '12 at 3:14

2 Answers 2

up vote 14 down vote accepted

You can use lsof to understand who's opening so many files. Usually it's a (web)server that opens so many files, but lsof will surely help you identify the cause.

Once you understand who's the bad guy you can

If output from lsof is quite huge try redirecting it to a file and then open the file

Example

lsof > ~/Desktop/lsof.log
vim ~/Desktop/lsof.log
share|improve this answer
8  
For the lazy: lsof | awk '{ print $2; }' | uniq -c | sort -rn | head –  itsadok Nov 27 '12 at 6:10
    
I got the same error and using ulimit doesn't work. The tail -F command still returns the error. I increased the limit from 1024 to 3000 so I would imagine that I have enough room by then... I guess I'd have to reboot! –  Alexis Wilke Jan 26 '13 at 11:41
7  
I found itsadok's line helpful, but I think you should sort first (because uniq only works with adjacent lines), run uniq, then sort again. So lsof | awk '{ print $2; }' | sort -rn | uniq -c | sort -rn | head. –  Tyler Collier Feb 2 '13 at 0:45
    
Sorting and counting up the most files open is definitely the best thing to do. Show process name as well as pid: '''lsof | awk '{ print $2 " " $1; }' | sort -rn | uniq -c | sort -rn | head -20''' –  gaoithe Dec 1 at 11:34

In case anyone else needs it...

ulimit -a

Will display all current limits. Specifically ulimit -n 70000 will set the file descriptor limit.

Also...

cat /proc/sys/fs/file-max

Will display/set the kernel limit if edited.

sudo echo 200000 > /proc/sys/fs/file-max

A much more detailed explanation can be found at...

How do I increase the open files limit for a non-root user?

share|improve this answer
    
ulimits are there so you can keep tight control over resource use in your system. It is best to increase them individually for processes you know will need to use many file descriptors. By keeping them tight in testing you will find processes which might steadily leak file descriptors over time. Note also that file handles are used for any device access in unix/linux. e.g. every network socket open by a process uses a file handle. That explains why you can hit the "too many open files" in case of regular file-system files as well as any device files such as network connections. –  gaoithe Dec 1 at 11:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.