140
BashINFOCommonSignalHIGH confidence

User-defined signal 2 (SIGUSR2)

Production Risk

Without a handler, terminates the process; always trap in long-running services.

What this means

Exit code 140 (128+12) indicates the process received SIGUSR2. Like SIGUSR1, this signal has no predefined meaning and is available for application-defined use.

Why it happens
  1. 1Another process sent kill -USR2 PID
  2. 2A profiler or debugging tool uses SIGUSR2 to trigger a heap dump
How to reproduce

Sending SIGUSR2 to a process with no handler.

trigger — this will error
trigger — this will error
#!/bin/bash
sleep 100 &
PID=$!
kill -USR2 $PID
wait $PID
echo "Exit: $?"

expected output

Exit: 140

Fix

Trap SIGUSR2 for secondary operational controls

WHEN Writing a service with multiple signal-based controls

Trap SIGUSR2 for secondary operational controls
#!/bin/bash
dump_status() {
  echo "=== Status at $(date) ===" >> /tmp/myapp-status.txt
  echo "PID: $" >> /tmp/myapp-status.txt
}
trap dump_status USR2

while true; do sleep 1; done

Why this works

SIGUSR1 and SIGUSR2 provide two independent, application-defined signal channels; use them for different operational actions.

Sources
Official documentation ↗

GNU Bash Manual — Signals

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

← All Bash errors