Crash (computing)
A crash is when a computer program, or a whole computer system, stops working because of an error it cannot get past.[1] Crashes come from software bugs, such as a program reading memory it is not allowed to use, and from faulty hardware or device drivers.[2][3]
A crashed program usually closes suddenly, and anything it held only in memory, such as unsaved work, is lost.[4][5] When the operating system itself crashes, the whole computer stops working.[3]
Kinds of crash
The word covers two levels of failure. An application crash ends one program, while a system crash stops the whole operating system.
| Kind | What stops | Common names |
|---|---|---|
| Application crash | One running program (a process) | Segmentation fault, "core dumped" |
| System crash | The operating system and every program on it | Kernel panic on Unix-like systems, bug check or blue screen on Windows |
Crash or hang
A hang is a related failure in which the program keeps running but stops responding.
A 1990 study of UNIX programs drew the line this way. A program crashed if it ended and left a core file (a saved copy of its memory), and it hung if it kept running but produced no output while input was waiting.[6]
On Apple platforms, a hang is almost always caused by long-running work on the program's main thread.[7] The main thread is the thread that handles incoming events and updates the user interface.[7]
Other meanings
In hard disk drives, a head crash is a physical failure, not a software one. It happens when the read/write head touches the spinning disk surface.[8] See hard disk drive failure.
Common causes
Apple describes a crash as the sudden end of an app when it tries to do something that is not allowed.[1] Sometimes the processor cannot run the code, as with a division by zero. At other times the operating system, the programming language, or the programmer's own checks stop the program on purpose.[1]
Common causes include:
- Invalid memory access. The program reads or writes an address it may not use, such as a null pointer or an address past the end of its data. This often ends in a segmentation fault.[2]
- Arithmetic errors. An operation such as division by zero can stop the program.[2] Python, for example, raises an exception when it detects a division by zero.[9]
- Unhandled exceptions. In languages with exception handling, an error that no code catches can end the program. In Python, the interpreter then ends the program (or returns to its interactive prompt) and prints a stack trace showing where the error happened.[9] In Java, by default, an uncaught exception prints a stack trace and ends only the thread it happened in, and the program keeps running until its other ordinary (non-daemon) threads finish.[10]
- Stack overflow. If a thread uses up its stack, often through very deep recursion (a function calling itself over and over), Linux sends it the signal for an invalid memory access.[11]
- Failed checks. An assertion is a check the programmer writes into the code. In C, a failed assertion prints an error and ends the program on purpose.[12]
- Resource limits. The operating system may stop a program that uses more CPU time or memory than allowed.[2][1] See out of memory.
- Hardware and drivers. On Windows, a faulty hardware device, its driver, or related software can cause a system crash.[3]
How a crashed program is stopped
On Unix-like systems, the hardware and the kernel work together to stop a faulty program. The kernel is the core of the operating system, and a signal is a short message the kernel sends to a process.[13]
- The program runs an instruction that breaks a rule, such as loading from an address outside its memory.
- The hardware detects the bad access and traps into the kernel. A trap moves control from the program to the kernel, which then decides what to do.[14]
- The kernel sends the process a signal that names the problem, such as
SIGSEGVfor an invalid memory access.[13] - If the program has set up a handler for that signal, the handler runs. A handler is code in the program that responds to a signal. Otherwise the kernel takes the signal's default action.[13]
- For crash signals, the default action ends the process and writes a core dump, a file holding an image of the process's memory at that moment.[15]
Crash signals
The Linux manual lists the default action for each standard signal. "Core" means the process ends and leaves a core dump, and "Term" means it simply ends.[13][15]
| Signal | Meaning | Default action |
|---|---|---|
SIGSEGV |
Invalid memory reference | Core |
SIGBUS |
Bus error (bad memory access) | Core |
SIGFPE |
Wrong arithmetic operation | Core |
SIGILL |
Illegal instruction | Core |
SIGABRT |
Abort signal from abort(3), usually called by the program itself |
Core |
SIGKILL |
Kill signal | Term |
Which signal a given hardware fault produces is not documented and can differ between processor types. An invalid memory access that gives SIGSEGV on one machine may give SIGBUS on another.[13]
A program may catch most signals with its own handler. The exceptions are SIGKILL and SIGSTOP, which cannot be caught, blocked, or ignored.[13]
Why one crash does not stop the others
Memory protection keeps a crash inside one process. Each process has its own address space (the range of memory addresses it can use) and cannot touch the memory of other processes or of the kernel.[16]
System crashes
A system crash happens when the kernel itself hits an error it cannot handle safely. Memory protection shields the kernel from programs, but it does not shield the kernel from its own bugs.
Windows bug checks
Windows halts when it meets a condition that makes safe operation impossible. Microsoft calls this a bug check, also known as a system crash, kernel error, or stop error.[3] The stop screen shows a stop code and, when available, the name of the module that was running. If it can, Windows then writes a dump file of memory and shows its progress as a percentage.[3]
Linux oops and panic
On Linux, a kernel error prints a report called an oops, which contains a stack trace that points to the faulty line of kernel code.[17] After an oops the kernel may try to keep running or may panic, meaning it stops completely. The panic_on_oops setting chooses between the two, and even when the kernel tries to continue, it panics after a set number of oopses (10,000 by default).[18]
An administrator can also have the kernel reboot a set number of seconds after a panic.[19]
Kernel design
Kernel structure affects how far one fault spreads. Microkernels wall off parts of the operating system from each other, and may be more reliable than typical monolithic kernels, where these parts are not separated.[16]
Finding the cause
Engineers study what a program left behind to find out why it crashed. The main sources are:
- memory dumps, such as core dumps;
- stack traces;
- crash reports.
Core dumps and crash reports
A core dump can be loaded into a debugger such as the GNU Debugger. The debugger then shows the program's state at the moment it ended.[15]
Crash reports on Apple platforms record the exception type, the thread that crashed, and stack traces.[2] A step called symbolication replaces raw memory addresses in the report with function names and line numbers.[2]
Saving a program's memory after a crash is an old idea. In 1951, the Whirlwind I computer displayed its memory on a screen when a program crashed, and a camera photographed the screen onto microfilm.[20]
Crash reporting at scale
Software makers collect crash reports from users' machines to find the bugs that matter most. Microsoft's Windows Error Reporting service, described in 2009, handled reports from about a billion machines and collected billions of reports in ten years.[20]
- Bucketing. Reports that likely come from the same bug are grouped into a bucket, ideally one bug per bucket.[20]
- Gradual collection. Most reports send only a bucket identifier. The service asks for a minidump (a small memory and stack dump) or a full dump only when developers need more.[20]
- Priorities. Reports follow a Pareto pattern, where a small number of bugs cause most reports. For Windows Vista, the top 500 buckets held 65% of all reports.[20]
Windows Vista developers fixed more than 5,000 bugs found this way in beta releases.[20]
Crashes and saved data
A crash in the middle of saving can leave stored data broken. This is called the crash-consistency problem.[5] A file system often needs several separate disk writes for one change, and the system may crash between any two of them.[5]
File systems use two main fixes:
- Checking after restart. Older systems let errors happen and repaired them at the next boot with a checker such as
fsck. This scans the whole disk and cannot fix every problem.[5] - Journaling. A journaling file system first writes a note describing the change to a log, then makes the change. After a crash it replays the changes recorded in the log, so recovery depends on the size of the log, not the disk.[5]
Journaling is the file system name for write-ahead logging, which records a change in a log before applying it to its final location. File system designers took the idea from databases.[5]
According to one standard textbook, the first file system to use journaling was Cedar.[5]
Crash failures in distributed systems
In fault-tolerant and distributed systems, "crash" has a precise meaning as one of several failure models. A failure model is an assumption about how a part of the system may misbehave.
Faults, errors, and failures
The field separates three terms.[21]
- A failure is when a system departs from its expected behavior.
- An error is any part of the system's state that does not meet its specification.
- A fault is any cause that can lead to an error, such as a bug or a broken part.
Failure models
A textbook classification by Tanenbaum and van Steen, based on work by Cristian (1991) and Hadzilacos and Toueg (1993), ranks failures by how badly a server can misbehave.[22]
| Failure type | What the server does |
|---|---|
| Crash failure | Works correctly, then halts |
| Omission failure | Fails to respond, receive, or send messages |
| Timing failure | Responds outside the allowed time |
| Response failure | Gives a wrong value or follows the wrong steps |
| Arbitrary failure | Produces any response at any time |
The last row matches the Byzantine fault model. Crash failures are the least harmful case, because once the server halts, nothing more is heard from it.[22]
Detecting a crash
Other machines usually learn of a crash only by noticing silence. Detection relies on timeouts, which assume messages arrive within some time limit.[21] In a fully asynchronous system, with no time limits, a slow machine cannot be told apart from a crashed one, which makes some problems impossible to solve.[21]
Fail-stop and fail-fast
Richard Schlichting and Fred Schneider defined the fail-stop processor in 1983. When it fails, it never produces a wrong result. It does only two visible things:[4]
- It stops running.
- Its internal state and its volatile memory (memory that loses its contents when the processor fails) are lost.
Stable storage, by contrast, survives any failure. Other processors can read it and continue the work.[4]
Jim Gray applied the same idea to software in 1985. A fail-fast module either works correctly or detects the fault, signals failure, and stops.[23]
Replication
Crash-only failures are cheaper to tolerate than arbitrary ones. In the state-machine approach, a service is copied onto machines. When every copy gets the same requests in the same order, all copies keep the same state and give the same replies.[21] To survive failed copies, the service needs
Here is the number of copies and is the number of copies that may fail. Byzantine failures need more copies so that correct copies always form a majority.[21]
Designing for crashes
Since no large system can be guaranteed never to crash, many designs plan for crashes and recover from them quickly.[24]
Restarting
Restarting often works because many bugs in mature software depend on rare timing or conditions. Gray called these Heisenbugs.[23] He studied a fault-tolerant spooler (a program that queues jobs, such as print jobs, for processing) and found that only 1 of 132 software faults failed again on retry.[23]
Gray also counted the causes of outages. In his 1985 study of more than 2,000 Tandem systems, software caused 25% of reported outages and system administration caused 42%.[23]
Tools restart crashed programs automatically.
- The service manager systemd can restart a service whose process exits with an error code or is killed by a signal, including on a core dump.[25]
- Erlang supervisors keep their child processes alive by restarting them. Under the
one_for_onestrategy, only the child that ended is restarted.[26]
Crash-only software
George Candea and Armando Fox proposed crash-only software in 2003. Such a program has only one way to stop, which is to crash, and only one way to start, which is to recover.[24] To make this safe, all important state lives in separate stores that are themselves crash-safe, and components tolerate crashes of their peers.[24]
Testing and security
Crashes matter both when testing software and when defending it against attack.
Fuzz testing
Fuzz testing feeds programs random input and watches for crashes and hangs.[6] The study that named it, published in 1990, crashed or hung about a quarter to a third of the UNIX utility programs tested on each system.[6]
Security risks
A crash that an outsider can trigger is a security problem. A null pointer dereference usually ends the process, so an attacker who sends crafted input can shut down a service, which is a denial-of-service attack.[27] In rare cases, the same bug can let an attacker read or change memory, or run code.[27]
Writes past the end of a block of memory, such as a buffer overflow, break memory safety in a similar way. They can crash a program, and in some cases they let an attacker run code.[28]
References
- Understanding Crashes and Crash Logs (WWDC18 session 414), Apple Developer, 2018.
- Understanding the exception types in a crash report, Apple Developer Documentation.
- Bug Checks (Stop Code Errors), Microsoft Learn.
- Fail-Stop Processors: An Approach to Designing Fault-Tolerant Computing Systems, R. D. Schlichting and F. B. Schneider, ACM Transactions on Computer Systems, 1983.
- Crash Consistency: FSCK and Journaling, R. Arpaci-Dusseau and A. Arpaci-Dusseau, Operating Systems: Three Easy Pieces.
- An Empirical Study of the Reliability of UNIX Utilities, B. P. Miller, L. Fredriksen, B. So, Communications of the ACM, 1990.
- Understanding hangs in your app, Apple Developer Documentation.
- What Happens During a Hard Drive Head Crash, Rossmann Group.
- Execution model, Python documentation.
- Design of the Shutdown Hooks API, Oracle, Java SE 8 documentation.
- sigaltstack(2), Linux manual page, man7.org.
- assert(3), Linux manual page, man7.org.
- signal(7), Linux manual page, man7.org.
- Segmentation, R. Arpaci-Dusseau and A. Arpaci-Dusseau, Operating Systems: Three Easy Pieces.
- core(5), Linux manual page, man7.org.
- The Abstraction: Address Spaces, R. Arpaci-Dusseau and A. Arpaci-Dusseau, Operating Systems: Three Easy Pieces.
- Bug hunting, The Linux Kernel documentation.
- Documentation for /proc/sys/kernel/, The Linux Kernel documentation.
- Documentation for /proc/sys/kernel/ (kernel.txt), kernel.org.
- Debugging in the (Very) Large: Ten Years of Implementation and Experience, K. Glerum et al., SOSP, 2009.
- Availability, S. Krakowiak, Middleware Architecture with Patterns and Frameworks.
- Lecture notes on Tanenbaum and van Steen, Distributed Systems, Chapter 8, Pace University.
- Why Do Computers Stop and What Can Be Done About It?, J. Gray, Tandem Technical Report 85.7, 1985.
- Crash-Only Software, G. Candea and A. Fox, HotOS IX, 2003.
- systemd.service, freedesktop.org.
- Supervisor Behaviour, Erlang System Documentation.
- CWE-476: NULL Pointer Dereference, MITRE.
- CWE-787: Out-of-bounds Write, MITRE.
