MacOS – Why does lsof exceed kern.maxfiles

command linemacosmojave

Running Mojave 10.14.3 I notice there are currently more files open than the maxfiles allowed. How is this possible? In this case I do not have any symptoms or error messages, but in the past I have seen an error message about too many open files, and that time when I checked, lsof was exactly 10000.

Side node: Is there any harm in increasing maxfiles?

$ sysctl kern.maxfiles
kern.maxfiles: 10000
$ lsof | wc
   13242  124035 1982117

Best Answer

lsof lists more than just file handles. Most notably, it includes program text mapped into all processes (e.g, the executable and all libraries it's using). There are a lot of these mappings in most GUI processes -- I count over 270 for the Finder, for instance -- and they don't consume file handles.

If you believe you are hitting the system's open file limit, go ahead and change kern.maxfile. However, it's more likely that you're hitting the per-process open file limit, which defaults to a lower number (7168 on my system) and can be changed using ulimit.