Speed up the shutdown process in OS X

A quick adjustment of the timeout values for key processes can greatly speed up otherwise laggy shutdowns in OS X.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
4 min read

When you shut down your Mac, OS X will attempt to cleanly exit programs and background services; however, under some circumstances this can take an exceptionally long time, so that the system waits for minutes before finally shutting down. Sometimes this is the system waiting for an interaction such as you saving a document, but at other times it is because background services have stopped responding and the system is waiting a predetermined amount of time before forcing them to quit.

Generally OS X should take only a few seconds to shut down, so if your system is consistently taking a long time, that suggests a problem that needs to be addressed. Sometimes this can simply be a problematic peripheral device or two, or it could be from some faulty configuration of your system. In these cases, you should attempt some basic troubleshooting procedures to help identify and fix the problem.

However, if you encounter lengthy shutdowns regularly but at more random intervals, then they may be situational and may be caused by the system waiting on some background processes to exit.

By default, the system will wait for background processes to end on their own, but if not then it will send such processes a kill signal after 20 seconds, and if these processes are timing out at different intervals, this can extend a shutdown to a number of minutes.

Therefore, for some background processes that tend to hang up more than others, simply changing this default 20-second time to a lower value will cause the system to exit these processes earlier. While forcing processes to quit is not the best practice, the system is already gearing up to do this during shutdown. Again, OS X only allows the process a 20-second window to exit in, and then the system will kill the process forcefully.

The background services that seem to be common culprits in such timeouts are those that handle interprocess communication, authentication management, and disk and network resource activity. In OS X these include the following:

  • AppleEvents -- This allows processes to communicate with and command each other (and is the basis for AppleScript). It may time out from interruptions in interprocess communication (for example, if one process is forced to quit when events are being managed).
  • securityd -- This manages access to keychains and other security authorizations, and may time out if waiting for user interaction for some authentication request.
  • mDNSResponder -- Manages multicast DNS actions, including automatic discovery of network servers and services. This may time out from problems with the local network configuration.
  • diskarbitrationd -- The disk arbitrator monitors the mounting and accessibility of local filesystems, and may time out from a fault in the drives being used, or if a drive goes offline or into sleep mode and takes a while to wake up.
  • Apple ID authentication -- manages the verification of your Apple ID for various services; may time out from poor network access or lack of response from Apple's servers.

The management of these processes' timeouts is done by the system launcher process launchd, which holds the 20-second default timeout for processes. By instructing the launcher to shorten this period even by half, you can significantly speed up shutdowns that are lagging because of these processes.

To change the timeouts, you will need to modify the launch daemon files the system uses for these services, so first be sure you have a backup of your system, and then run the following commands, which you can copy and paste (each command is two lines) into the OS X Terminal utility (in the Applications > Utilities folder):

sudo defaults write /System/Library/LaunchDaemons/c\
om.apple.coreservices.appleevents ExitTimeOut -int 5

sudo defaults write /System/Library/LaunchDaemons/c\
om.apple.securityd ExitTimeOut -int 5

sudo defaults write /System/Library/LaunchDaemons/c\
om.apple.mDNSResponder ExitTimeOut -int 5

sudo defaults write /System/Library/LaunchDaemons/c\
om.apple.diskarbitrationd ExitTimeOut -int 5

sudo defaults write /System/Library/LaunchAgents/com.\
apple.coreservices.appleid.authentication ExitTimeOut -int 5

In these commands as written above, the timeout value is set to "5," meaning the system will wait 5 seconds before killing a process during shutdown, but you can change this to any integer value greater than zero (a value of zero disables the timeout, so it would wait indefinitely). Note that these are "sudo" commands, which means when you run the first one you will need to provide your admin password (which will not show in the Terminal when prompted), but then will not need to provide the password for the subsequent commands.

Paste both lines of each command given above into the Terminal, changing the value of 5 to another number if you wish (you can run the commands again at any time with different values). When finished, restart your computer, and then see whether or not this improves your shutdown times.

To undo these actions, you can run the commands again but with a value of 20, or you can run the following commands to remove the "ExitTimeOut" settings entry, which is by default not included in these launch daemon and agent scripts:

sudo defaults delete /System/Library/LaunchDaemons/c\
om.apple.coreservices.appleevents ExitTimeOut

sudo defaults delete /System/Library/LaunchDaemons/c\
om.apple.securityd ExitTimeOut

sudo defaults delete /System/Library/LaunchDaemons/c\
om.apple.mDNSResponder ExitTimeOut

sudo defaults delete /System/Library/LaunchDaemons/c\
om.apple.diskarbitrationd ExitTimeOut

sudo defaults delete /System/Library/LaunchAgents/com\
.apple.coreservices.appleid.authentication ExitTimeOut

Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.