Segmentation fault (SIGSEGV)
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.
- 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.
- 2A bug in a shell extension or a command executed by the script.
- 3Hardware memory errors (rare).
Running a buggy C program from a shell script.
#!/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
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.
✕ Ignore the error
A segmentation fault is a critical bug that indicates severe memory corruption and can lead to unpredictable behavior or security vulnerabilities.
GNU Bash Manual
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev