Published on

How To Find the Process/es Hogging The Most Files on *nix Systems

Authors

Today when trying to interact with a machine on our cluster I tried to run a command but got the error: ...too many open files.... I know that the lsof command can be used to list the open files but I was not 100% sure how to pinpoint the process/es keeping the most files open.

After a bit of Googling I ended up with:

lsof | awk '{ print $1 " " $2; }' | uniq -c | sort -rn | head

Running this on my Mac (which does not have too many files open) I get the following:

 408 Google 435
 335 Dropbox 381
 142 UserEvent 317
 120 AppleSpel 598
  73 Google 443
  61 Alfred 366
  60 iTerm2 828
  59 accountsd 343
  58 Finder 323
  57 Google 483

The columns from left to right are:

  1. The number of files open
  2. The name of the program that has those files open
  3. The process id of the program with these files open