Terminated (SIGTERM)
Exit code 143 is caused by the SIGTERM signal (signal 15), indicating that the process was asked to terminate gracefully. It is the default signal sent by the `kill` command. The exit code is 128 + 15.
- 1A user or script ran `kill PID` on the process.
- 2Process managers like `systemd` or supervisors send SIGTERM to stop a service.
A process manager stopping a service.
#!/bin/bash # This is hard to trigger from a single script. # Conceptually, another terminal would run: # kill $ echo "Running, waiting for SIGTERM..." sleep 300
expected output
Terminated Exit: 143
Fix
Trap SIGTERM for graceful shutdown
WHEN The script needs to perform cleanup before exiting
#!/bin/bash
cleanup() {
echo "Caught SIGTERM, cleaning up..."
# Perform cleanup actions here
exit 143
}
trap cleanup SIGTERM
echo "Running, PID is $"
sleep 300Why this works
The `trap` builtin allows the script to catch the signal and execute a cleanup function before it terminates, ensuring a clean shutdown.
✕ Ignore the signal in a long-running service
Ignoring SIGTERM can prevent your service from shutting down gracefully, potentially leading to data corruption or a forceful shutdown via SIGKILL from the service manager.
GNU Bash Manual
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev