A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
abort terminates the program abnormally. It raises the SIGABRT signal. It does not flush stdio buffers. It does not call atexit handlers. It does not close open files gracefully. On most systems, it produces a core dump: a snapshot of the process's memory that a debugger can inspect. abort is the last resort. You call it when the program has reached an impossible state and continuing would cause more damage than stopping.
#include <stdio.h>#include <stdlib.h>void cleanup(void) {printf("This atexit handler will NOT run.\n");}int main(void) {atexit(cleanup);printf("Before abort.\n");fflush(stdout);fprintf(stderr, "Fatal: impossible state reached. Aborting.\n");abort();printf("This line is never reached.\n");return 0;}
The atexit handler did not run. The final printf did not execute. The shell reports "Aborted (core dumped)". The exit status is 134 (128 + 6, where 6 is SIGABRT). A core file was written to disk, which you can inspect with gdb ./abort_demo core to see the exact call stack and variable state at the moment of abort.
exit is for normal termination: the program finished its work, or encountered a recoverable error that it handled. abort is for impossible states: an assertion that should never fail did fail, a data structure is corrupted beyond repair, a security invariant was violated. abort preserves the memory state for post-mortem debugging. exit cleans up and moves on. Choose based on whether you need the core dump.
abort is the emergency brake. Pull it when the alternative is worse. The core dump it produces is your forensic evidence. Next: assert, the debugging macro that calls abort when an invariant is violated.
Finish the lesson once you have worked through the material. This awards ★ 20 XP.