143
BashWARNINGNotableExit CodeHIGH confidence

Terminated (SIGTERM)

What this means

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.

Why it happens
  1. 1A user or script ran `kill PID` on the process.
  2. 2Process managers like `systemd` or supervisors send SIGTERM to stop a service.
How to reproduce

A process manager stopping a service.

trigger — this will error
trigger — this will error
#!/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

Trap SIGTERM for graceful shutdown
#!/bin/bash
cleanup() {
    echo "Caught SIGTERM, cleaning up..."
    # Perform cleanup actions here
    exit 143
}
trap cleanup SIGTERM

echo "Running, PID is $"
sleep 300

Why this works

The `trap` builtin allows the script to catch the signal and execute a cleanup function before it terminates, ensuring a clean shutdown.

What not to do

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.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Bash errors