launchctl limit maxfiles vs sysctl kern.maxfilesperproc

4

1

I'm trying to understand MacOS High Sierra behavior. Here is the output on my machine:

launchctl limit maxfiles
maxfiles 256 unlimited

sysctl kern.maxfiles
kern.maxfiles: 12228

sysctl kern.maxfilesperproc
kern.maxfilesperproc: 10240

My questions are:

  1. Is maxfiles 256 from launchctl limit maxfiles is a per-process limit?
  2. Why maxfiles by "launchctl limit maxfiles" differs from kern.maxfiles and kern.maxfilesperproc?
  3. Which limit (maxfiles 256 or kern.maxfilesperproc: 10240) is applied for an application that is started manually by a user from Applications?

DenisL

Posted 2018-10-24T13:51:39.233

Reputation: 51

Answers

4

  1. Is maxfiles 256 from launchctl limit maxfiles a per-process limit?

Yes. launchctl limit maxfiles prints the per-process soft and hard limits as reported by getrlimit(2), whose man page says:

     A resource limit is specified as a soft limit and a hard limit.  When a
     soft limit is exceeded a process may receive a signal (for example, if
     the cpu time or file size is exceeded), but it will be allowed to con-
     tinue execution until it reaches the hard limit (or modifies its resource
     limit).

getrlimit(2) is apparently where the shell built-in command ulimit gets its information.

  1. Why does launchctl limit maxfiles differ from kern.maxfiles and kern.maxfilesperproc?

launchctl limit maxfiles reports the per-process soft and hard limits that launchd imposes on processes. launchd apparently imposes a soft limit of 256 and an "unlimited" hard limit, which really means it's only limited by kern.maxfilesperproc in the kernel, not by launchd.

kern.maxfiles is the limit of total file descriptors on the entire system; the sum total of all the open files for all processes plus all the files the kernel has open for its own purposes.

  1. Which limit (maxfiles 256 or kern.maxfilesperproc: 10240) is applied for an application that is started manually by a user from Applications?

An application started manually by a user launching an app from the GUI will inherit the launchd-imposed soft limit of 256 and "unlimited" hard limit, so its hard limit will effectively be kern.maxfilesperproc, assuming there's enough free file descriptors on the system that the app can hit its limit before the entire system hits kern.maxfiles.

Processes (apps) can also use system calls to adjust their soft limits once they're running. So the soft limit of 256 is just the default at launch time, and your app/process may immediately increase its own soft limit.

Spiff

Posted 2018-10-24T13:51:39.233

Reputation: 84 656