Speed up the shutdown process in OS X
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/com.apple.coreservices.appleevents ExitTimeOut -int 5
sudo defaults write /System/Library/LaunchDaemons/com.apple.securityd ExitTimeOut -int 5
sudo defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ExitTimeOut -int 5
sudo defaults write /System/Library/LaunchDaemons/com.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/com.apple.coreservices.appleevents ExitTimeOut
sudo defaults delete /System/Library/LaunchDaemons/com.apple.securityd ExitTimeOut
sudo defaults delete /System/Library/LaunchDaemons/com.apple.mDNSResponder ExitTimeOut
sudo defaults delete /System/Library/LaunchDaemons/com.apple.diskarbitrationd ExitTimeOut
sudo defaults delete /System/Library/LaunchAgents/com.apple.coreservices.appleid.authentication ExitTimeOut