139
BashCRITICALExit CodeHIGH confidence

Segmentation fault (SIGSEGV)

What this means

Exit code 139 indicates a Segmentation Fault, which is triggered by the SIGSEGV signal (signal 11). This means the program tried to access a memory location that it was not allowed to access. The exit code is 128 + 11.

Why it happens
  1. 1A bug in a compiled program (e.g., in C or C++) that leads to dereferencing a null pointer, buffer overflows, or use-after-free errors.
  2. 2A bug in a shell extension or a command executed by the script.
  3. 3Hardware memory errors (rare).
How to reproduce

Running a buggy C program from a shell script.

trigger — this will error
trigger — this will error
#!/bin/bash
# Create and compile a C program that causes a segfault
cat <<EOF > segfault.c
#include <stddef.h>
int main() {
    int *ptr = NULL;
    *ptr = 1; // Dereference NULL pointer
    return 0;
}
EOF
gcc segfault.c -o segfaulter
./segfaulter
echo "Exit: $?"

expected output

Segmentation fault
Exit: 139

Fix

Debug the underlying program

WHEN A program consistently causes a segmentation fault

Debug the underlying program
gdb ./my_buggy_program

Why this works

A debugger like GDB can be used to run the program and inspect its state at the moment of the crash to identify the faulty code.

What not to do

✕ Ignore the error

A segmentation fault is a critical bug that indicates severe memory corruption and can lead to unpredictable behavior or security vulnerabilities.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Bash errors