Alarm clock (SIGALRM)
Production Risk
Mostly used in C programs via alarm(); in shell scripts, prefer timeout or read -t.
Exit code 142 (128+14) indicates the process received SIGALRM from the alarm() syscall or setitimer(). If no handler is installed, the process terminates.
- 1A timeout set via alarm() or setitimer() expired
- 2Another process sent kill -ALRM PID
- 3Shell read -t (timed read) uses SIGALRM internally on some shells
alarm() timeout expires with no handler.
#!/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
# 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
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.
GNU Bash Manual — Signals
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev