4

Is there a way I can find what file handles emacs has open, and close these references? Or even better, find where they are being open?

Emacs is keeping handles to a large number of files (a leak) that I don't have corresponding buffers to. My standard method of closing a buffer has been using the kill-buffer command.

Context:

I am having a reoccurring issue, where after a day or two of being open I can no longer do any file operations in emacs, due to a "Too many open files" error when creating a pipe. I am on OSX 10.10.4, Emacs 25.0.50 installed with homebrew.

Here is a sample of emacs' open files according to Activity Monitor (double click on emacs and select "Open Files and Ports").

/Users/Ash/Dropbox/org /Users/Ash/Dropbox/org /Users/Ash/Dropbox/org /Users/Ash/Dropbox/org /Users/Ash/Documents/workspace/roboclub/Federation-Place /Users/Ash/Documents/workspace/roboclub/Federation-Place /Users/Ash/Documents/workspace/roboclub/Federation-Place /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript/status /Users/Ash/Dropbox/org /Users/Ash/Dropbox/org /Users/Ash/Dropbox/org /Users/Ash/Dropbox/org /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript/status /Users/Ash/Documents/workspace/roboclub/Federation-Place /Users/Ash/Documents/workspace/roboclub/Federation-Place /Users/Ash/Documents/workspace/roboclub/Federation-Place /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript/status /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript/status /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript/status /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript/status /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript /Users/Ash/Documents/workspace/roboclub/Federation-Place/web/site/src/javascript 

There are actually many more files open, but you can see that they are being repeated. (Also these are folders, not sure why that is).

Update

The following are my file limits:

$ ulimit -n 4096 $ sysctl -a | grep files kern.maxfiles: 20480 kern.maxfilesperproc: 10240 kern.num_files: 4496 

And my open files:

$ lsof | awk '{print $1 "-" $2}' | sort | uniq -c | sort -nr | head -10 728 Google-345 508 Google-551 430 Mail-353 418 Skype-12098 356 Dock-361 350 Emacs-8847 207 Dropbox-637 176 Google-22455 176 Google-21229 165 Google-26072 

Emacs is the only program having issues, yet doesn't seem to have a comparatively high file count.

1 Answer 1

2

This error is probably related to OS restrictions on max open files and unrelated to Emacs. You can check what processes are running under Emacs with this command:

M-x list-processes 

The most common tool to see which file is opened by which process/program, use lsof tool at the system command prompt (outside Emacs):

lsof +f 

the +f shows only filesystem entries (files and directories) and not all network pipes too. In any case, to fix the max open files, you will have to play with a few settings. Start with

sysctl -A | grep maxfiles 

and increase the values for

kern.maxfiles = 12288 kern.maxfilesperproc = 10240 

by editing (as sudo) this file

/etc/launchd.conf 

and this line with suitable values (instead of 64K shown below)

limit maxfiles 65536 65536 

then reboot OS X (logging off alone won't be enough for launchd settings). Fine tuning the max capacities is an art and is greatly dependent on what all things your installed programs are doing on your machine on your behalf!

OS X has a manpage for sysctl with lots more details.

3
  • 1
    Thanks for your response. I have seen a lot of recommendations to increase the maxfiles values, but my thought process is if I am getting to 10240, what's to say that 65536 is any better? Thanks for the lsof pointer, I will use it as I get the error next and see if it sheds insight into why there are so many files being used. Commented Aug 5, 2015 at 2:11
  • 1
    How do you know if its any better before trying? Commented Aug 5, 2015 at 3:47
  • Fair point. I have updated the question with my ulimit, sysctl and lsof output. Commented Aug 16, 2015 at 6:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.