- 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.
- 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.
- 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.