142
BashWARNINGNotableSignalHIGH confidence

Alarm clock (SIGALRM)

Production Risk

Mostly used in C programs via alarm(); in shell scripts, prefer timeout or read -t.

What this means

Exit code 142 (128+14) indicates the process received SIGALRM from the alarm() syscall or setitimer(). If no handler is installed, the process terminates.

Why it happens
  1. 1A timeout set via alarm() or setitimer() expired
  2. 2Another process sent kill -ALRM PID
  3. 3Shell read -t (timed read) uses SIGALRM internally on some shells
How to reproduce

alarm() timeout expires with no handler.

trigger — this will error
trigger — this will error
#!/bin/bash
# Implement a shell timeout with SIGALRM
( sleep 5; kill -ALRM $ ) &
ALARM_PID=$!
# Do some work
sleep 10
kill $ALARM_PID 2>/dev/null  # Cancel alarm if work finished
echo "Exit: $?"

expected output

Alarm clock
Exit: 142

Fix 1

Use the timeout command instead of manual SIGALRM

WHEN Adding timeouts to shell commands

Use the timeout command instead of manual SIGALRM
# Prefer timeout over manual alarm() management
timeout 5s your_command
if [ $? -eq 124 ]; then
  echo "Timed out" >&2
fi

Why this works

The timeout utility is simpler and more reliable than manually managing SIGALRM.

Fix 2

Use read -t for timed input

WHEN Waiting for user input with a timeout

Use read -t for timed input
if read -t 10 -p "Press Enter within 10s: " response; then
  echo "Got: $response"
else
  echo "Timed out"
fi

Why this works

read -t sets a timeout without needing to manage SIGALRM directly.

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