"Segmentation Fault (Core Dumped)" — A Practical Diagnosis Order

Segfaults mean a process touched memory it shouldn't. For most people it's not your bug to debug — it's the environment: bad libs, missing resources, or stack limits. Here's the triage order.

What you'll see

Root causes

Environment/library mismatch (the usual culprit for shipped software)

The binary was built against different library versions than it runs with (or a CPU without the expected extensions). ldd <bin> and comparing against a working host finds it.

Resource limits: stack size or vm/max_map_count

Deep recursion (and some JVM/Postgres setups) exceed the default 8MB stack: ulimit -s shows it. Raising it fixes 'segfault only under heavy work' patterns.

Actual application bugs (your code)

For software you build: null derefs, bad pointers, array overruns. gdb + core dump or ASAN builds localize them; the core pattern (ulimit -c unlimited) captures the evidence.

Fix it

  1. Quick environment checks first
    ldd <binary> 2>&1 | grep -i 'not found' ; ulimit -s ; uname -m
  2. Reproduce under gdb for a real backtrace
    ulimit -c unlimited ; gdb -batch -ex run -ex bt <binary> 2>&1 | tail -15
  3. Suspect stack limits on heavy-work crashes
    ulimit -s unlimited && <binary>   # or raise it in systemd: LimitSTACK=16M
  4. For your own code: rebuild with AddressSanitizer
    # gcc -fsanitize=address -g ... — ASAN points at the exact bad access instead of just SIGSEGV

Field note

Segfault on one host but not another is almost always libs or CPU features, not randomness. Containers: check the image's glibc vs the binary's build target (debian vs alpine musl is the #1 shipped-binary segfault).

Common questions

Do I need to debug this if it's not my program?

No — triage the environment first: ldd for missing libs, ulimit for limits, host arch. If the environment is sane, capture the core and file a report with the backtrace; don't hand-fix vendor binaries.

Where did my core file go?

Most distros pipe cores to systemd-coredump or apport now: coredumpctl list shows them (coredumpctl gdb <pid> to inspect). ulimit -c unlimited re-enables classic core dumps where supported.

Ship it right the first time

Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.

Browse the template store →

One-time. Yours to modify. Instant download from the NinjaOps template store.