Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A solution for Mac OS X process limits UNIX
I work with Terminal a lot, and often have 30 to 40 windows open, each running my shell and ssh. Add in all the other processes, and I quickly exceed the 100 maxprocperuid limit that OS X defaults to.

There have been many proposed solutions to this. You can, for instance, in your shell startup scripts override the limit for that shell instance, and you can run more than 100 processes from that shell, but when you launch a new window, the parent process that launches all apps for you in the GUI is still limited to that 100 process per user limit, and the new window will fail to launch your shell. It usually fails with the error: login: fork: Resource temporarily unavailable.

There are two phases to fixing this problem. First you must change the overall OS limits for maxproc and maxprocperuid to higher values, and then you must make WindowServer run in an environment with the limits raised.

[robg adds: I have not tested this one, nor do I intend to! If you're going to experiment with it, I recommend you have a good backup first, just in case...]

System Wide
OS X 10.3 now supports the standard /etc/sysctl.conf. This means you can just put new values into this file and reboot. This is what the file looks like:


% cat /etc/sysctl.conf <br>
# Turn up maxproc <br>
kern.maxproc=2048 <br>

# Turn up the maxproc per user <br>
kern.maxprocperuid=512 <br>
Daemons /etc/rc.common
All of the daemons that are started via /System/Library/StartupItems are started with the default maxproxperuid of 100. This might not normally be a problem, as root may not run a ton of processes, but it does matter when sshd is started up. On OS X, sshd is started out of xinetd. A quick way to affect the environment of xinetd, and all other daemons as well, is to put ulimit -u 512 at the top of /etc/rc.common. If you preferred, you could just edit the startup script for xinetd instead, which is in /System -> Library -> StartupItems -> IPServices -> IPServices.

Here is a snippet of the top of my /etc/rc.common file:


#######################
# Configure the shell #
#######################

ulimit -u 512

##
# Be strict
##
WindowServer
Every process you run from the GUI is launched by WindowServer. So we need to make WindowServer launch in such a way that it has its limits raised. I cannot determine what actually launches WindowServer. Its parent process is mach_init, and I can find no way to modify how it is launched directly. You can, however, write a wrapper script for WindowServer. This is a shell script that is launched instead of WindowServer itself which sets the limits properly, then launches the original WindowServer as normal.
  1. Become root on command line.

  2.  % cd /System/Library/Frameworks/
     % cd ApplicationServices.framework/Frameworks/
     % cd CoreGraphics.framework/Resources/
    robg adds: Yes, you can do that as one long cd command; I snipped it apart for narrower display width.

  3. Type mv WindowServer WindowServer.orig

  4. Type vi WindowServer ... below is the script I used; the last two lines should be entered as one long line with no extra spaces in it:
    #!/bin/zsh
    ulimit -u 384
    /System/Library/Frameworks/ApplicationServices.framework/
     Frameworks/CoreGraphics.framework/Resources/WindowServer.orig $*
    
  5. Type chmod a+rx WindowServer

  6. Type reboot
How I Tested
To quickly test if my solution was working I ran a bunch of sleep0 processes in the background. This was able to reproduce the problem for me on demand before the fix. I'd open one shell window, launch over 100 sleeps, and then try to launch a new Terminal window, and it would fail. After the fix, it works.
    •    
  • Currently 2.75 / 5
  You rated: 3 / 5 (8 votes cast)
 
[86,270 views]  

A solution for Mac OS X process limits | 11 comments | Create New Account
Click here to return to the 'A solution for Mac OS X process limits' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A solution for Mac OS X process limits
Authored by: fxt on Nov 25, '03 12:44:14PM

> OS X 10.3 now supports the standard /etc/sysctl.conf

this file doesn't exist on my 10.3.1 rig. should one just create this file? if so, with what permissions? where is it documented that panther now supports sysctl.conf? or do i have an errant installation?

fxt



[ Reply to This | # ]
A solution for Mac OS X process limits
Authored by: pdm on Nov 25, '03 02:50:39PM

You have to create it, it doesn't exist by default. I'm not
sure where it is documented. To see the types of values
that can go in the file though you can run sysctl -a

Here is mine:

14:48 EST | serrano:~>cat /etc/sysctl.conf
# Turn up maxproc
kern.maxproc=2048

# Turn up the maxproc per user
kern.maxprocperuid=512

---
-pdm



[ Reply to This | # ]
UPDATE: A solution for Mac OS X process limits
Authored by: pdm on Nov 25, '03 02:56:00PM
I tried to submit an update to this before it was published but it didn't work. My original hint misses updating daemons like sshd. I've got the updated hint on my website here.

Sorry for the confusion!

---
-pdm

[ Reply to This | # ]

Sorry about that!
Authored by: robg on Nov 26, '03 01:34:08PM

I've updated the main story now -- I didn't see your udpate in the queue when I ran the first one (there are still quite a few things in the queue!).

But hopefully I got the edit in properly; if not, drop me an email with corrections...

regards;
-rob.



[ Reply to This | # ]
A solution for Mac OS X process limits
Authored by: hgd on Oct 05, '04 03:34:49AM
I have modified this solution in a way that may make it more stable across OS upgrades. WindowServer tends to get overwritten, so you'd have to reinstall the wrapper script after each upgrade. That's why I left the WindowServer binary as is and created a wrapper script called WindowServer.local:

#!/bin/sh

ulimit -u 512

/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/WindowServer "$*"
I then configured mach_init to launch this script by modifying the file /etc/mach_init.d/WindowServer.plist. This is what it looks like now:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>ServiceName</key>
        <string>com.apple.windowserver</string>
        <key>Command</key>
        <string>/System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/WindowServer.local</string>
</dict>
</plist>
This works fine as well. I'm not sure if /etc/mach_init.d/WindowServer.plist isn't overwritten during upgrades as well, so this may all amount to nothing ;-)

[ Reply to This | # ]
A solution for Mac OS X process limits
Authored by: jnathan on Oct 08, '04 01:38:45PM

I've just began looking into this as it's awfully frustating. There may be a simpler fix.

/System/Library/StartupItems/CoreGraphics is a script called as part of the StartupItems process.

the line:
ConsoleMessage -b /System/Library/CoreServices/SystemStarter/QuartzDisplay.bundle/QuartzDisplay


Starts the set of QuartzDisplay components which include WindowServer. I'm going to try setting ulimit -u in the CoreGraphics script.



[ Reply to This | # ]
A solution for Mac OS X process limits
Authored by: hgd on Oct 16, '04 07:24:35AM

So, does that work for you? I doubt it, because the file already sources rc.common. If you set the ulimit in rc.common, it should thus already affect WindowServer, but (apparently) it doesn't ...



[ Reply to This | # ]
A solution for Mac OS X process limits: sysctl
Authored by: chrismiles on Nov 21, '05 12:44:14PM
An alternative way to increase the kernel limit is to use the sysctl command. This is handy if you only want to set it temporarily (lasts until system reboot). Example:

sudo sysctl -w kern.maxprocperuid=256
After the above, you can then increase your limit in a local shell (or add to your ~/.bashrc), with:

ulimit -u 256
Cheers, Chris Miles

[ Reply to This | # ]
A solution for Mac OS X process limits
Authored by: wlf on Jul 07, '06 04:23:34PM

In Mac OS X 10.4, the proper place to put sysctl settings is in /etc/sysctl.conf. This file is processed by /etc/rc at system boot time.

Say

kern.maxproc=2048
kern.maxprocperuid=1024

in /etc/sysctl.conf.

Then, the proper way to set the system-wide "max user processes" is to say

limit maxproc 1000

in /etc/lanuchd.conf, which is processed by launchd at boot time.

After reboot, login, open Terminal, and run

ulimit -a

and you'll see "max user processes" as expected.



[ Reply to This | # ]
A solution for Mac OS X process limits
Authored by: wlf on Jul 07, '06 04:24:53PM

Make that /etc/launchd.conf.



[ Reply to This | # ]
A solution for Mac OS X process limits
Authored by: outspoken on Jul 19, '06 11:53:07AM

OS X Server 10.4.7:

/etc/sysctl-macosxserver.conf

check limit with:
launchctl limit

use above comments for adding temporarily if needed instead of commiting changes to system via conf file.

/etc/launchd.conf does not exist on OS X Server 10.4.7 and none of the affore mentioned files appear to exist on my OS X Client 10.4.7 computer.



[ Reply to This | # ]