Linux SIGSEGV — Segmentation Fault Signal Handling & Debugging
Errorsignal
Overview
Complete guide to Linux SIGSEGV (signal 11) segmentation fault: causes, debugging with GDB and core dumps, and common patterns in C/C++ programs.
Key Details
- SIGSEGV (signal 11) is sent when a process accesses memory outside its allowed address space
- The kernel's memory management unit (MMU) detects the invalid access and sends the signal
- Default action is to terminate the process and generate a core dump (if enabled)
- Common in C/C++ programs due to manual memory management
- Core dumps are stored according to /proc/sys/kernel/core_pattern
Common Causes
- Dereferencing NULL pointer (most common cause)
- Accessing array out of bounds (buffer overflow or underflow)
- Using memory after it has been freed (use-after-free)
- Stack overflow from infinite recursion
- Writing to read-only memory (e.g., string literal modification)
Steps
- 1Enable core dumps: ulimit -c unlimited
- 2Compile with debug symbols: gcc -g -O0 program.c -o program
- 3Run under GDB: gdb ./program, then 'run', then 'bt' at crash for backtrace
- 4Analyze core dump: gdb ./program core — then 'bt' for backtrace
- 5Use Valgrind for memory error detection: valgrind --tool=memcheck ./program
Tags
linuxsigsegvsegfaultsignal-11debugging
More in Signal
Frequently Asked Questions
The program accessed invalid memory and was killed. A core dump file was created containing the program's memory state for debugging.