Error Codes Wiki

Linux SIGSEGV — Segmentation Fault Signal Handling & Debugging

Errorsignal

About Linux SIGSEGV

Complete guide to Linux SIGSEGV (signal 11) segmentation fault: causes, debugging with GDB and core dumps, and common patterns in C/C++ programs. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.

Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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). Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Enable core dumps: ulimit -c unlimited. Compile with debug symbols: gcc -g -O0 program.c -o program. Run under GDB: gdb ./program, then 'run', then 'bt' at crash for backtrace. Analyze core dump: gdb ./program core — then 'bt' for backtrace. Use Valgrind for memory error detection: valgrind --tool=memcheck ./program. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.

This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.

Quick Answer

What does 'Segmentation fault (core dumped)' mean?

The program accessed invalid memory and was killed. A core dump file was created containing the program's memory state for debugging.

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

  1. 1Enable core dumps: ulimit -c unlimited
  2. 2Compile with debug symbols: gcc -g -O0 program.c -o program
  3. 3Run under GDB: gdb ./program, then 'run', then 'bt' at crash for backtrace
  4. 4Analyze core dump: gdb ./program core — then 'bt' for backtrace
  5. 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.