π ** Exit Status Code = 143 in Bash**
π― What You Will Learnβ
- Understand what exit status code = 143 means in Bash.
- Learn how SIGTERM (signal 15) works β the graceful termination signal.
- Differentiate
143from similar codes:130(SIGINT) and137(SIGKILL). - Detect when processes are ended normally by system shutdown, Docker stop, or admin command.
- Handle and trap SIGTERM safely inside scripts.
- Apply best practices in WordPress VPS automation, ensuring clean exits during restarts, backups, or container stops.
1. 5W + 1H Frameworkβ
| Element | Description |
| What | Exit code 143 means the process was terminated gracefully via SIGTERM (signal 15). |
| Why | SIGTERM is sent to stop a process politely, giving it a chance to clean up before exiting. |
| Who | Used by systemd, Docker, Kubernetes, and admins when stopping services or automation scripts. |
| When | When a process receives SIGTERM (kill, docker stop, systemctl stop) instead of abrupt SIGKILL. |
| Where | Common in background jobs, cron, Docker containers, or managed WordPress VPS tasks. |
| How | Bash computes 128 + signal_number β 128 + 15 = 143. |
2. Prerequisitesβ
Before starting, you should:
- Understand signals in Bash (
SIGINT,SIGTERM,SIGKILL). - Know how to use commands like
kill,ps, andtrap. - Be familiar with background processes (
&) and service management (systemctl,docker stop). - Have access to a Linux VPS environment.
3. Core Syntax and Examplesβ
π§© Definitionβ
Exit code 143 = process terminated by SIGTERM (signal 15) β graceful shutdown signal.β
Example 1 β Sending SIGTERM with killβ
sleep 60 &
kill -15 $!
wait $!
echo $?
Expected Output:
143
Explanation:
Process was found and asked to terminate (SIGTERM), not forced.
Bash reports exit code 143 = 128 + 15.β
Example 2 β Graceful Docker Stopβ
docker run --name test -d ubuntu sleep 300
docker stop test
docker inspect test --format='{{.State.ExitCode}}'
Expected Output:
143
Explanation: Docker sends SIGTERM to the container before SIGKILL (after timeout). Container exits gracefully β exit code 143. Use Case (WordPress VPS): Gracefully stopping a running PHP-FPM or Redis container.β
Example 3 β systemd Service Stopβ
systemctl stop php8.3-fpm
echo $?
Expected Output (in logs):
php8.3-fpm[PID]: received SIGTERM, shutting down
Explanation:
systemd uses SIGTERM to stop services like PHP-FPM or MySQL gracefully.
The exit code is reported as 143.
Use Case:
When rebooting a VPS or restarting the stack with systemctl restart lsws.β
Example 4 β Handling SIGTERM in Scriptβ
#!/bin/bash
trap "echo 'Graceful stop detected'; exit 143" SIGTERM
echo "Running backup..."
sleep 60
echo "Backup completed."
Run it:
bash safe_exit.sh &
kill -15 $!
wait $!
echo $?
Expected Output:
Running backup...
Graceful stop detected
143
Explanation: The script traps SIGTERM, performs cleanup, and exits with 143 intentionally. Use Case: Gracefully stop WordPress backup jobs or WP-CLI updates during system shutdown.β
Example 5 β System Sending SIGTERM Before Rebootβ
sudo reboot
Expected in logs:
systemd[1]: Stopping php8.3-fpm.service...
php-fpm[PID]: received SIGTERM, exiting gracefully
Explanation: During reboot, systemd sends SIGTERM to running processes. They log exit 143 as part of controlled shutdown.β
4. Common Scenarios Triggering Exit Code 143β
| Scenario | Example | Description |
| Manual stop | kill PID or kill -15 PID | User requests graceful stop |
| System service stop | systemctl stop mysql | systemd sends SIGTERM |
| Docker container stopped | docker stop | Docker sends SIGTERM before kill |
| VPS reboot | reboot or shutdown | OS sends SIGTERM to all |
| Cron cleanup | Script terminates itself cleanly | Uses exit 143 |
| Monitoring agent shutdown | service telegraf stop | SIGTERM issued to daemon |
5. WordPress VPS Use Casesβ
| Use Case | Example | Explanation |
| Graceful PHP-FPM stop | systemctl stop php8.3-fpm | Ends requests safely |
| WP container shutdown | docker stop wp-site | Graceful exit of web app |
| Cron job interrupted | Admin sends kill | Script exits 143 |
| Redis cache stop | systemctl stop redis-server | SIGTERM sent for safe data flush |
| WP backup abort | kill -15 PID | Backup stops safely, not corrupted |
| LiteSpeed reload | systemctl reload lsws | Workers gracefully end connections |
6. Troubleshooting Matrixβ
| Symptom | Likely Cause | Diagnostic Command | Fix |
| Exit 143 logged | Graceful termination (SIGTERM) | journalctl -xe | Expected normal behavior |
| Process ends mid-task | Admin stop or reboot | last -x | Re-run job after reboot |
| Docker container exits 143 | Container stop issued | docker logs <container> | Normal; verify graceful shutdown logs |
| Script halts unexpectedly | Received SIGTERM | trap handling missing | Add cleanup trap |
| WP tasks stop on cron overlap | Duplicate execution | Add lockfile mechanism |
7. Best Practicesβ
- Handle SIGTERM gracefully:
trap "echo 'SIGTERM received, exiting cleanly...'; exit 143" SIGTERM
- Use traps for cleanup:
- Delete temp files.
- Close connections.
- Log event before exit.
- Avoid force-killing processes:
Use
killorsystemctl stopinstead ofkill -9. - For containers: Always let Docker send SIGTERM before SIGKILL (default 10s timeout). Extend timeout if needed:
docker stop -t 30 wp-site
- Automate logging of exits:
echo "$(date): Process exited with code $?" >> /var/log/exit_status.log
- Use lock files in scripts to prevent multiple overlapping runs.
8. Quick Lab β Simulate Exit Code 143β
Step 1: Create a test scriptβ
nano /root/exit143_test.sh
Step 2: Insertβ
#!/bin/bash
trap "echo 'SIGTERM received, cleaning up...'; exit 143" SIGTERM
echo "Starting task..."
sleep 60
echo "Finished task."
Step 3: Run in backgroundβ
bash /root/exit143_test.sh &
pid=$!
Step 4: Send SIGTERMβ
kill -15 $pid
wait $pid
echo $?
Expected Output:
Starting task...
SIGTERM received, cleaning up...
143
Explanation: Script exited gracefully when SIGTERM was received β exit code 143 confirms safe shutdown.β
9. Cheat Sheetβ
| Exit Code | Meaning | Description |
0 | Success | Normal completion |
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 binary or path |
130 | Terminated by SIGINT | Manual interrupt (Ctrl+C) |
137 | Killed by SIGKILL | Forceful kill or OOM |
139 | Segmentation fault | Memory access violation |
143 | Terminated by SIGTERM | Graceful termination |
10. Mini-Quizβ
- What signal number corresponds to exit code 143?
- Whatβs the difference between SIGTERM and SIGKILL?
- Which system command sends SIGTERM to stop services gracefully?
- How can you handle SIGTERM in a Bash script?
- Why is exit code 143 considered a βnormalβ stop rather than an error?