Are OS X shutdown cause and sleep cause numbers listed/explained anywhere?

The numbers in which I'm most interested

  • -2
  • 0
  • 3
  • 5

… I might add to that shortlist.

What do those numbers mean; where might we find authoritative explanations?

Somewhere in Apple open source, maybe?

Background

There's a suggested answer for -60, a question about -81, a debatable suggested answer for -108, discussion of -128, -72, -62, -30, -2, 0, 3 … and so on, but unless I'm missing something:

  • nothing like an Apple-provided list of explanations of the commonly seen numbers.

Examples

Three messages recently sent by kernel on a MacBookPro5,2:

2014-03-31 09:04:49.000 kernel[0]: Previous Shutdown Cause: 5
2014-03-31 11:01:24.000 kernel[0]: Previous Sleep Cause: 5
2014-03-31 14:47:00.000 kernel[0]: |Previous Shutdown Cause: -60

Possibly relevant to some cause numbers

Error codes in http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/MacErrors.h

  • that's in Apple open source for Mac OS X 10.6.2 but not in open source for Mac OS X 10.6.3
  • the source code for 10.6.2 is almost identical to what's installed under MacOSX10.8.sdk
  • it may be sensible to treat some of those error codes as deprecated.

Solution 1:

The precise meaning of the codes is not publicly documented, although according to @grgarside's website for Shutdown Causes, the causes for the ones listed in the question are:

  • 5

    Correct Shut Down. Shutdown was initiated, from the OS X Shut Down menu or other shutdown command. This normally does not indicate an issue with your system.

  • 3

    Hard shutdown. Check power button.

  • 0

    Power disconnected. Check power supply/battery.

  • -2

    vTypErr = -2, /*invalid queue element*/

    Most likely it's a hardware issue such as faulty logic board, a video card or RAM.

    Related:

    • Previous Shutdown Cause: -2
    • macOs Sierra "previous shutdown cause: -2"?

For a full up-to-date list, see Shutdown Causes.

See also: List Of Mac OS X Error Codes.


Here on Ask Different, there have been a number of questions about shutdown causes:

  • -60: What is shutdown cause -60?

    Bad master directory block (badMDBErr).

  • -62: Kernel: "Previous shutdown cause: -62"

    Watchdog timer detected unresponsive application, restarting the system.

  • -64: Random Kernel Panics with Shutdown Cause: -64

  • -104: Shutdown cause: -104

    Possibly linked to battery issue.

  • -108: What is Shutdown Cause -108?

    Likely memory issue.

  • -112: Shutdown cause -112

    Restart cause logged when it freezes in a hard manner.

  • -128:

    • Tracking down hard shutdown cause—software? hardware? overheat?
    • Shutdown Cause -128

    In general, -128 is unknown hardware problem, but commonly it can be related either to memory issue or to the battery time span (at the end of its useful life).


If you've got negative numbers very often, Apple is more keen to get your Mac to the repair, as it usually indicates problem with your hardware.


General suggestions in case of further problems:

  • Reset the SMC and Reset NVRAM (which you did).
  • Run an Apple Hardware Test.
  • Log a kernel panic.
  • Install EtreCheck app to find serious problems on your Mac.

Solution 2:

So the kbase articles on System Error codes date back to the days of PowerPC processors, which apparently needed a lot more bits to report all of the potential hardware errors that could cause a shutdown. Starting with the advent of Intel boards, all shutdowns are tagged with an 8-bit code, if the normal software shutdown flags are not recorded. A positive code indicates a software or HID initiated shutdown, while a negative code (in the range of -1 to -127) indicates hardware-related Intel SMC-initiated shutdown. A -128 shutdown code indicates a hardware-related shutdown of unknown cause.

The 0 shutdown code resides in a liminal space between the hardware and the user; it signifies a sudden loss of power which can either be caused by a hardware failure or user action (if you want to demonstrate this for yourself, try popping the battery out of an old MacBook or MacBook Pro while it's on and unplugged, or pulling the power cord out of an iMac while it's running, then rebooting the computer and checking Console.app. A 0 Sleep Cause results when a MacBook/Pro/Air puts itself into SafeSleep using the last bit of reserve battery power before full system shutdown in order to preserve the contents of RAM in the

/var/vm/sleepimage

file. Unless you happen to connect your MagSafe adapter immediately after the computer goes to sleep, this code is pretty well guaranteed to be followed a 0 Shutdown Cause in the system.log.

Some of the hardware shutdown codes are unique to specific models of computer depending on their configuration because they refer to a specific sensor or device that exists only in that model– when I worked for Apple we were told that Intel was responsible for assigning the codes and wasn't particularly free with the information sharing on that count, even with Apple Engineering. So we pretty much had to figure out the obscure ones on our own.

Previous Shutdown Cause 5 and 3 are holdovers from the PowerPC days- because they're initiated by the user, the OS is still responsible for reporting them.

Code 5 is a clean, user initiated software shutdown, e.g. by selecting Shut Down from the  menu, or pressing the power button and selecting Shut Down in the pop-up window, or holding down controloptioncommandeject, or typing

sudo halt

at the command prompt. Similarly, a Previous Sleep Cause of 5 indicates any clean user-initiated sleep, from the  menu or a hot corner or the command line or closing the lid and triggering the hall-effect sensor in the top case of a MacBook/Pro/Air.

Code 3 is a "dirty" Shutdown, which can be caused by any user-initiated Reboot of the computer, or by forcing a hardware computer halt by holding down the power button for 5+ seconds.