π ** Exit Status Code = 139 in Bash**
π― What You Will Learnβ
- Understand what exit status code = 139 means in Bash.
- Learn what a segmentation fault (SIGSEGV) is and why it occurs.
- Differentiate exit
139from137(killed by SIGKILL). - Identify typical causes like invalid memory access, corrupted binaries, or miscompiled programs.
- Debug 139 errors in Bash, PHP, MySQL, and WP-CLI within WordPress VPS environments.
- Learn how to prevent and safely recover from segmentation faults.
1. 5W + 1H Frameworkβ
| Element | Description |
| What | Exit status 139 means the process terminated due to a segmentation fault (signal 11 / SIGSEGV) β an attempt to access invalid memory. |
| Why | It indicates the process tried to read/write a memory location it shouldnβt, due to bugs, bad pointers, or corrupt binaries. |
| Who | System administrators, DevOps engineers, or developers running compiled or memory-intensive software like PHP, MySQL, Redis, or custom binaries. |
| When | When a program crashes unexpectedly β often during high memory use or misconfiguration. |
| Where | Seen in Bash scripts, system services, or WP-CLI tasks running compiled binaries (PHP, MySQL, Redis, etc.). |
| How | Bash 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, andgdb. - 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β
| Scenario | Example | Description |
| Null pointer dereference | In C or binary programs | Program tries to write to invalid memory |
| Corrupted binary | truncate or disk corruption | Executable invalid |
| PHP memory overflow | php -r 'while(true)...' | Unbounded memory usage |
| MySQL crash | mysqldump or SELECT * | Bug or buffer overrun |
| Redis/LSCache crash | redis-server segfault | Memory corruption |
| Kernel/driver bug | During load spike | Low-level issue |
5. WordPress VPS Use Casesβ
| Use Case | Example | Explanation |
| PHP-FPM crashed | service php8.3-fpm restart β returns 139 | Memory violation in PHP binary |
| WP-CLI crash | wp search-replace on large DB | PHP engine hit a segfault |
| MySQL corruption | mysqldump interrupted | InnoDB or plugin caused memory crash |
| Redis segfault | redis-cli flushall | Redis memory pool damaged |
| LSCache worker crash | systemctl restart lsws | LiteSpeed module segfault |
| Dockerized WP process crash | Container exits 139 | Memory error inside PHP container |
6. Troubleshooting Matrixβ
| Symptom | Likely Cause | Diagnostic Command | Fix |
| βSegmentation fault (core dumped)β | Binary corruption | file /usr/bin/php | Reinstall package |
| Random PHP crashes | Extension bug | php -m | Disable suspicious extensions |
| MySQL crashes on large query | Buffer overflow | dmesg / journalctl -xe | Update or tune memory |
| WP-CLI stops at 139 | Memory overflow | htop / free -h | Increase PHP memory limit |
| Core dump created | Debug symbol missing | gdb core | Analyze or report upstream |
| Happens only on certain VPS | Kernel bug | uname -a | Update kernel or OS |
7. Best Practicesβ
- 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
- Check binary integrity:
debsums php8.3-fpm
- Prevent low-memory crashes:
- Add swap space.
- Optimize WP database queries.
- Avoid simultaneous high-load processes.
- Keep packages updated:
apt update && apt upgrade -y
- Isolate crashing components:
- Run each heavy WP task separately.
- Use container limits to contain fault domains.
- 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 Code | Meaning | Description |
0 | Success | Command executed successfully |
1 | General error | Non-specific failure |
2 | Misuse of shell builtins | Syntax or structure error |
126 | Command cannot execute | Permission or binary issue |
127 | Command not found | Missing or invalid path |
130 | Terminated by SIGINT | Manual interrupt (Ctrl+C) |
137 | Killed by SIGKILL | Forced termination (OOM / kill -9) |
139 | Segmentation fault | Process crashed (SIGSEGV / memory violation) |
10. Mini-Quizβ
- What signal number corresponds to a segmentation fault?
- Whatβs the mathematical formula to derive exit code 139?
- Name two possible causes of segmentation faults in WordPress VPS.
- How do you inspect the details of a core dump?
- What is the difference between
kill -9(exit 137) and SIGSEGV (exit 139)?