On my Mac with OS X El Capitan 10.11.6, there are some issues that seem to be related to resource constraints. I have seen such things
error: cannot spawn or
unable to fork or
-bash: fork: retry: Resource temporarily unavailable
-bash: fork: Resource temporarily unavailable
Due to the fact that my system did not freeze or spit errors everywhere, I expected the number of processes I could perform to reach my limits.
$ ulimit -u
709 is a lot of processes, but I ran a lot of servers on my Mac, so it seemed possible that I used so many. I've tried this command, which prints out how many processes the user is performing (actually 1 more than the number of processes).
$ ps -xu $(id -ru) | wc -l
fork: Resource temporarily unavailable
OK, I could not execute this command, creating 3 processes. So I was probably at the process limit. And the error message did not start
-bash that was not the point
ulimit either. I have reached the system-wide limit
I could confirm this by running a shell as
$ id -ru
$ sudo -i
root# ps -xu 501 | wc -l
Yes, 706 <709, but
mdworker Processes come and go routinely, so it was conclusive enough to approach the border area.
How do I increase the limit on the number of processes I can run? I searched for answers and found articles that suggested creating a file
/Library/LaunchDaemons/limit.maxproc.plist with this content:
I did that and restarted and now
$ ulimit -u
Which would be great, except
$ sysctl kern.maxproc
THIS IS DANGEROUS, This means that the entire system is still limited to a maximum of 1064 processes, but a single user may create more than that. When the system reaches the maximum number of processes, it generally crashes quickly and in a very bad way. It is therefore very important that no user is allowed to create enough processes to complete the process table. On the Mac, the number of processes is limited to 2/3.
I found similar suggestions for the maximum number of open files
maxfilesperprocEven more dangerous because a single process may not nearly open the system-wide limit on the total number of open files.
The other problem is that if 709 processes were not enough, 1000 processes are probably not enough.
So, what's the right way to fix "Too many open files" or "Branching: Resource temporarily unavailable" on OS X El Capitan?