Skip to main content

πŸ“˜ ** Exit Status Code = 139 in Bash**



🎯 What You Will Learn​

  1. Understand what exit status code = 139 means in Bash.
  2. Learn what a segmentation fault (SIGSEGV) is and why it occurs.
  3. Differentiate exit 139 from 137 (killed by SIGKILL).
  4. Identify typical causes like invalid memory access, corrupted binaries, or miscompiled programs.
  5. Debug 139 errors in Bash, PHP, MySQL, and WP-CLI within WordPress VPS environments.
  6. Learn how to prevent and safely recover from segmentation faults.

1. 5W + 1H Framework​

ElementDescription
WhatExit status 139 means the process terminated due to a segmentation fault (signal 11 / SIGSEGV) β€” an attempt to access invalid memory.
WhyIt indicates the process tried to read/write a memory location it shouldn’t, due to bugs, bad pointers, or corrupt binaries.
WhoSystem administrators, DevOps engineers, or developers running compiled or memory-intensive software like PHP, MySQL, Redis, or custom binaries.
WhenWhen a program crashes unexpectedly β€” often during high memory use or misconfiguration.
WhereSeen in Bash scripts, system services, or WP-CLI tasks running compiled binaries (PHP, MySQL, Redis, etc.).
HowBash adds 128 + signal_number β†’ 128 + 11 = 139 after SIGSEGV termination.

2. Prerequisites​

Before proceeding, you should:

  • Know exit code structure: 128 + signal_number.
  • Understand what signals and process IDs are.
  • Know how to use commands like dmesg, journalctl, ulimit, and gdb.
  • Have experience debugging PHP/MySQL or Linux services in a WordPress VPS.

3. Core Syntax and Examples​

🧩 Definition​

Exit code 139 = Process terminated by SIGSEGV (signal 11) β€” segmentation fault.​

Example 1 – Simulated Segmentation Fault (C Program)​

Create a test file:

cat > segfault.c <<'EOF'
#include <stdio.h>
int main() {
int *ptr = NULL;
*ptr = 10; // invalid memory write
return 0;
}
EOF

gcc segfault.c -o segfault
./segfault
echo $?

Expected Output:

Segmentation fault (core dumped)
139

Explanation: The program tried to write to an invalid memory location (NULL pointer). Exit code 139 confirms a SIGSEGV crash.​

Example 2 – Corrupted Binary Execution​

cp /bin/ls /tmp/broken_ls
truncate -s 100 /tmp/broken_ls
/tmp/broken_ls
echo $?

Expected Output:

Segmentation fault (core dumped)
139

Explanation: The binary was corrupted (truncated). When executed, it caused an invalid instruction β†’ segmentation fault. Use Case (WordPress VPS): If /usr/bin/php or wp-cli.phar becomes corrupted during an update.​

Example 3 – PHP Process Crash​

php -r 'while(true) { $a[] = str_repeat("x", 1024*1024); }'
echo $?

Expected Output:

Segmentation fault (core dumped)
139

Explanation: PHP ran out of memory or hit an internal memory corruption bug, leading to a crash. Exit code 139 reported to Bash. Use Case: When wp import or wp search-replace runs huge data operations on limited RAM VPS.​

Example 4 – MySQL Server Crash​

mysql -u root -p -e "SELECT * FROM huge_table;"
echo $?

Expected Output:

Segmentation fault (core dumped)
139

Explanation: MySQL process crashed due to a plugin or buffer overflow. Exit 139 confirms a software-level segmentation fault.​

Example 5 – Checking System Logs​

dmesg | tail -10

Expected Output Example:

[121212.3456] php-fpm[2456]: segfault at 8 ip 00007f28b12345 sp 00007ffc9e8d error 4 in libc-2.31.so

Explanation: System kernel log recorded the segmentation fault event with memory addresses. This is where debugging starts.​

4. Common Scenarios Triggering Exit Code 139​

ScenarioExampleDescription
Null pointer dereferenceIn C or binary programsProgram tries to write to invalid memory
Corrupted binarytruncate or disk corruptionExecutable invalid
PHP memory overflowphp -r 'while(true)...'Unbounded memory usage
MySQL crashmysqldump or SELECT *Bug or buffer overrun
Redis/LSCache crashredis-server segfaultMemory corruption
Kernel/driver bugDuring load spikeLow-level issue

5. WordPress VPS Use Cases​

Use CaseExampleExplanation
PHP-FPM crashedservice php8.3-fpm restart β†’ returns 139Memory violation in PHP binary
WP-CLI crashwp search-replace on large DBPHP engine hit a segfault
MySQL corruptionmysqldump interruptedInnoDB or plugin caused memory crash
Redis segfaultredis-cli flushallRedis memory pool damaged
LSCache worker crashsystemctl restart lswsLiteSpeed module segfault
Dockerized WP process crashContainer exits 139Memory error inside PHP container

6. Troubleshooting Matrix​

SymptomLikely CauseDiagnostic CommandFix
β€œSegmentation fault (core dumped)”Binary corruptionfile /usr/bin/phpReinstall package
Random PHP crashesExtension bugphp -mDisable suspicious extensions
MySQL crashes on large queryBuffer overflowdmesg / journalctl -xeUpdate or tune memory
WP-CLI stops at 139Memory overflowhtop / free -hIncrease PHP memory limit
Core dump createdDebug symbol missinggdb coreAnalyze or report upstream
Happens only on certain VPSKernel buguname -aUpdate kernel or OS

7. Best Practices​

  1. Enable core dumps for debugging:
ulimit -c unlimited

Core files will be saved for post-mortem analysis. 2. Use gdb for crash inspection:

gdb /usr/bin/php core

  1. Check binary integrity:
debsums php8.3-fpm

  1. Prevent low-memory crashes:
  • Add swap space.
  • Optimize WP database queries.
  • Avoid simultaneous high-load processes.
  1. Keep packages updated:
apt update && apt upgrade -y

  1. Isolate crashing components:
  • Run each heavy WP task separately.
  • Use container limits to contain fault domains.
  1. Automate monitoring:
tail -f /var/log/syslog | grep segfault


8. Quick Lab – Observe Exit 139​

Step 1: Create a C crash test​

cat > /root/crash.c <<'EOF'
int main() {
int *ptr = 0;
*ptr = 100;
return 0;
}
EOF

Step 2: Compile and run​

gcc /root/crash.c -o /root/crash
/root/crash
echo $?

Expected Output:

Segmentation fault (core dumped)
139

Explanation: You caused a memory access violation. The exit code confirms a SIGSEGV crash.​

9. Cheat Sheet​

Exit CodeMeaningDescription
0SuccessCommand executed successfully
1General errorNon-specific failure
2Misuse of shell builtinsSyntax or structure error
126Command cannot executePermission or binary issue
127Command not foundMissing or invalid path
130Terminated by SIGINTManual interrupt (Ctrl+C)
137Killed by SIGKILLForced termination (OOM / kill -9)
139Segmentation faultProcess crashed (SIGSEGV / memory violation)

10. Mini-Quiz​

  1. What signal number corresponds to a segmentation fault?
  2. What’s the mathematical formula to derive exit code 139?
  3. Name two possible causes of segmentation faults in WordPress VPS.
  4. How do you inspect the details of a core dump?
  5. What is the difference between kill -9 (exit 137) and SIGSEGV (exit 139)?