Executing compiled applications, command-line utilities, or Python/C++ scripts in Linux only to have the terminal abruptly terminate with the error: ‘Segmentation fault (core dumped)’ or ‘SIGSEGV (Signal 11)’ halts program execution. In Linux, a segmentation fault indicates that a process attempted to access a memory address that it does not own, attempted to write to a read-only memory segment, or exhausted its allocated stack space. The Linux kernel immediately issues signal 11 (SIGSEGV) and terminates the program to protect memory integrity. Resolving this issue involves diagnosing core dump files, repairing conflicting shared libraries, and troubleshooting software bugs.
Why Does Segmentation Fault (core dumped) Occur in Linux?
Linux processes operate inside virtual memory spaces managed by the Memory Management Unit (MMU). Common root causes for SIGSEGV include:
- Null Pointer Dereferences: A program attempting to read from or write to memory address
0x0(null pointer). - Buffer Overflows and Stack Exhaustion: Infinite recursive functions consuming all stack memory or array indexes writing outside allocated heap chunks.
- Mismatched Shared Libraries (ABI Incompatibilities): An executable compiled against one version of a shared library (e.g.
glibc,libssl, orlibstdc++) attempting to run against an incompatible library version installed on the system. - Corrupted Application Binaries: Incomplete package downloads or compilation errors producing damaged ELF binaries.
- Defective Hardware Memory: Faulty physical RAM causing random bit-flips in program address spaces during memory-intensive tasks.
Step 1: Inspect the System Journal for Fault Details
The Linux kernel logs critical segfault metadata including the instruction pointer (IP) and faulting library.
- Immediately after the crash occurs, query the system journal:
sudo dmesg -T | grep -i segfault - Alternatively, use
coredumpctlto inspect recent crashes:coredumpctl list - Review the output for the faulting executable and shared library:
app[12345]: segfault at 0 ip 00007f... sp 00007f... error 4 in libc.so.6 - The faulting address and library indicate whether the crash stems from core C runtime libraries, graphics drivers (NVIDIA/Mesa), or application code.
Step 2: Analyse the Core Dump Using GDB
The GNU Debugger (GDB) inspects the core dump to reveal the exact line of code or function that triggered the memory fault.
- Ensure
gdbis installed on your distribution:sudo apt install gdb # Ubuntu/Debian sudo dnf install gdb # Fedora/RHEL - Open the crash dump with GDB:
coredumpctl gdb <PID> - Or directly load the core file if generated in your working directory:
gdb /path/to/binary /path/to/core - In the GDB prompt, type
bt(backtrace) to print the call stack:(gdb) bt - The backtrace pinpointing the function name and line number reveals whether a specific dynamic library or user script caused the violation.
Step 3: Update and Reinstall Conflicting Shared Libraries
If the segfault points to a shared library (such as libssl.so or libc.so), updating or reinstalling the relevant packages resolves version drift.
- Check which package owns the faulting library:
dpkg -S /path/to/library.so # Debian/Ubuntu rpm -qf /path/to/library.so # RHEL/Fedora - Reinstall the package cleanly:
sudo apt install --reinstall package-name - Run
ldconfigto rebuild the dynamic linker cache:sudo ldconfig
Step 4: Check and Increase Stack Size Limits
If deep recursion triggers a segfault due to stack exhaustion, raising the shell stack limit can permit the program to complete.
- Check your current stack limit:
ulimit -s - Temporarily increase the stack size limit (e.g. from 8192 KB to unlimited):
ulimit -s unlimited - Re-run the program to see if it executes without faulting.
Step 5: Test Physical RAM for Bit-Flips
Random, non-reproducible segmentation faults across different software packages strongly suggest failing hardware RAM.
- Install
memtester:sudo apt install memtester - Run a memory stress test on available RAM:
sudo memtester 4096M 1 - If memory test failures are reported, reseat or replace the affected physical RAM modules.
Inspecting kernel segfault logs, backtracing with GDB, refreshing dynamic linker caches, and testing hardware memory eliminates segmentation faults in Linux.