Troubleshooting sleep in OS X

Several settings and system features govern the sleep mode in OS X and can prevent normal system sleep if either in use or used incorrectly.

System sleep in OS X is a convenient feature that saves power while preserving your work flow. This option has been available in Macs and other PC systems for years, and is especially useful for laptops where you might wish to conserve battery power. While computer sleep is nothing new, there are some details of how it is implemented in OS X that may help you troubleshoot situations where sleep does not behave as it should.

For Mac systems sleep is governed by the system management controller (SMC), which has a number of variables it uses to manage when disks spin down, what GPU to use, whether or not various sensors are enabled, and options for managing sleep behaviors. Some of these sleep behaviors include when the display and system go into sleep modes (these are set in the System Preferences), whether or not the system will use hibernate mode (enabled by default on laptops) and where it will store the hibernation file on the system.

Hibernate mode settings in OS X
The hibernate mode and sleep image settings are listed here in the output of the pmset -g command (click for larger view). Screenshot by Topher Kessler/CNET

To see these variables, open the Terminal and run the following command:

pmset -g

By default, the hibernatemode variable should be 0 for desktops and 3 for laptops, the difference being the mode for laptops enables the use of the hibernation file to store RAM contents and completely shut down the system, as a backup to normal sleep mode. A third potentially useful option here is the value of 25, which will have the system only use the hibernate file and thereby conserve more energy when asleep, with the drawback being longer sleep and wake times since the RAM contents need to be purged during sleep.

The sleep mode variable can be set to either 0, 3, or 25 by running the following command (be sure to only use one of these three values to avoid potential errors in the sleep process):

sudo pmset hibernatemode NUMBER

If your system is set to use hibernate mode and store the contents of RAM, then the SMC will also use a hibernation file, which is located in the folder designated by the hibernatefile variable for the SMC (usually the hidden /var/vm/ folder). To see this file, in the Finder choose "Go to Folder" from the Go menu, and then enter /var/vm/ in the field. When executed you will see a file called "sleepimage" that is the same size as the RAM in your computer (in other words, 4GB or 8GB if you have that amount of RAM installed).

If for some reason your system is not going into hibernation mode, or shuts down and reboots instead of restoring to a working state after going into hibernation, then you might benefit from deleting the sleepimage file in the /var/vm/ folder and allowing the system to recreate it.

Power Assertions in OS X
Running the pmset command will list the number of power assertions that are active on the system. In this case, the background process "helpd" for the help viewer has been holding a single "backgroundprocess" assertion for about 25 minutes (click for larger view). Screenshot by Topher Kessler/CNET

Another aspect of the system management controller that might affect system sleep and that's relatively new to OS X is the power assertions feature. This is an option in which a program or process can invoke an assertion to keep the system awake regardless of the SMC's settings in order to finish a task. To see these assertions, open the Terminal and run the following command:

pmset -g assertions

The output from this command will list the assertion types along with the number of each assertion that is invoked in the system. After this the output will list both processes that have invoked the assertions and any kernel-based assertions that might be active. If you have a Mac that will not go to sleep regardless of what settings you put in the Energy Saver system preferences, then it may be that a program is maintaining a power assertion that prevents it from doing so.

Power assertions in OS X
If you can identify a running process as holding a power assertion, then you can look it up in Activity Monitor and quit it if needed. In this case, the process id 5048 for the helpd process matches that found to be holding the power assertion in the Terminal output above (click for larger view). Screenshot by Topher Kessler/CNET

Troubleshooting power assertions is relatively simple, especially since any listed by the output of the pmset command above will include the name of the process along with its process ID (PID). These details can help you track down the program and determine how best to manage it. If it is a relatively benign background process such as the help viewer (helpd) or a hard-drive indexing program (mds), then you can use Activity Monitor to look up the process by name and PID, and then quit it. If you are unsure what the listed processes do, then be sure to look them up beforehand.

Another issue with Mountain Lion's use of power assertions is that these are used instead of more global features like disk activity when determining whether or not the system can go to sleep, and therefore the system may go to sleep mode in the middle of some tasks like importing pictures or otherwise transferring data if the developer has not programmed it to hold a power assertion when performing these tasks.

If you are using a program for which the system ignores its activity and goes to sleep, then you can either extend or disable the system's sleep timer, or you can use a program like Caffeine to keep an assertion active and thereby keep the system awake.



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.

Tags:
Computers
Read the full CNET Review

Mac OS X 10.8 Mountain Lion

The Bottom Line: Though it's not a complete system or interface overhaul, Mountain Lion's improved core apps and new features make it well worth the $19.99 price. / Read full review

About the author

    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.

     

    ARTICLE DISCUSSION

    Conversation powered by Livefyre

    Don't Miss
    Hot Products
    Trending on CNET

    Hot on CNET

    CNET's giving away a 3D printer

    Enter for a chance to win* the Makerbot Replicator 3D Printer and all the supplies you need to get started.