



Akernel panic (sometimes abbreviated asKP[1]) is a safety measure taken by anoperating system'skernel upon detecting an internalfatal error in which either it is unable to safely recover or continuing to run the system would have a higher risk of major data loss. The term is largely specific toUnix andUnix-like systems. The equivalent onMicrosoft Windows operating systems is astop error, often called a "blue screen of death".
Thekernel routines that handle panics, known aspanic() inAT&T-derived andBSD Unix source code, are generally designed to output anerror message to theconsole, dump an image of kernel memory to disk forpost-mortem debugging, and then either wait for the system to be manually rebooted, or initiate an automaticreboot.[2] The information provided is of a highly technical nature and aims to assist asystem administrator orsoftware developer in diagnosing the problem. Kernel panics can also be caused by errors originating outsidekernel space. For example, many Unix operating systems panic if theinit process, which runs inuser space, terminates.[3][4]
TheUnix kernel maintains internal consistency andruntime correctness withassertions as thefault detection mechanism. The basic assumption is that the hardware and the software should perform correctly and a failure of an assertion results in apanic, i.e. a voluntary halt to all system activity.[5] The kernel panic was introduced in an early version of Unix and demonstrated a major difference between the design philosophies of Unix and its predecessorMultics. Multics developerTom van Vleck recalls a discussion of this change with Unix developerDennis Ritchie:
I remarked to Dennis that easily half the code I was writing in Multics was error recovery code. He said, "We left all that stuff out. If there's an error, we have this routine called panic, and when it is called, the machine crashes, and you holler down the hall, 'Hey, reboot it.'"[6]

The originalpanic() function was essentially unchanged from Fifth Edition UNIX to theVAX-based UNIX 32V and output only an error message with no other information, then dropped the system into an endless idle loop. As the Unixcodebase was enhanced, thepanic() function was also enhanced to dump various forms of debugging information to the console.
A panic may occur as a result of a hardware failure or asoftware bug in the operating system. In many cases, the operating system is capable of continued operation after an error has occurred. If the system is in an unstable state, rather than risking security breaches and data corruption, the operating system stops in order to prevent further damage, which helps to facilitate diagnosis of the error and may restart automatically.[7]

After recompiling a kernel binary image fromsource code, a kernel panic whilebooting the resulting kernel is a common problem if the kernel was not correctly configured, compiled or installed.[8] Add-on hardware or malfunctioningRAM could also be sources of fatal kernel errors during start up, due to incompatibility with the OS or a missingdevice driver.[9] A kernel may also go intopanic() if it is unable to locate aroot file system.[10] During the final stages of kerneluserspace initialization, a panic is typically triggered if the spawning ofinit fails. A panic might also be triggered if the init process terminates, as the system would then be unusable.[11]
The following is an implementation of the Linux kernel final initialization inkernel_init():[12]
staticint__refkernel_init(void*unused){.../* * We try each of these until one succeeds. * * The Bourne shell can be used instead of init if we are * trying to recover a really broken machine. */if(execute_command){if(!run_init_process(execute_command))return0;pr_err("Failed to execute %s. Attempting defaults...\n",execute_command);}if(!run_init_process("/sbin/init")||!run_init_process("/etc/init")||!run_init_process("/bin/init")||!run_init_process("/bin/sh"))return0;panic("No init found. Try passing init= option to kernel. ""See Linux Documentation/init.txt for guidance.");}



Kernel panics appear inLinux like in otherUnix-like systems; however, serious but non-fatal errors can generate another kind of error condition, known as akernel oops.[13] In this case, the kernel normally continues to run afterkilling the offendingprocess. As an oops could cause some subsystems or resources to become unavailable, they can later lead to a full kernel panic.
On Linux, a kernel panic causes keyboard LEDs to blink as a visual indication of a critical condition.[14]
As of Linux 6.10, drm_panic was merged allowingDRM drivers to support drawing a panic screen to inform the user that a panic occurred. This allows a panic screen to appear even when a display server was running when the panic occurred.[15]
As of Linux 6.12, drm_panic was extended where the stack trace can be encoded as aQR code.[16]
When a kernel panic occurs inMac OS X 10.2 through 10.7, the computer displays a multilingual message informing the user that they need to reboot the system.[17] Prior to 10.2, a more traditional Unix-style panic message was displayed; in 10.8 and later, the computer automatically reboots and the message is only displayed as a skippable warning afterward. The format of the message varies from version to version:[18]
In macOS 10.8, if five new kernel panics occured within three minutes of the first one, the Mac would display aprohibitory sign for thirty seconds, and then shut down; this is known as a "recurring kernel panic".[19]
In all versions above 10.2, the text is superimposed on astandby symbol and is not full screen. Debugging information is saved inNVRAM and written to a log file on reboot. In 10.7 there is a feature to automatically restart after a kernel panic. In some cases, on 10.2 and later, white text detailing the error may appear in addition to the standby symbol.