The signals that matter most
- SIGTERM (15) — "please exit." Default of
kill. - SIGINT (2) — "the user pressed Ctrl+C."
- SIGHUP (1) — "your terminal closed," or, by convention, "reload your config."
- SIGKILL (9) — "die now." Cannot be caught.
- SIGSTOP / SIGCONT — uncatchable stop and continue signals. Use names because signal numbers vary across systems.
- SIGUSR1 / SIGUSR2 — application-defined. Read the target program's current documentation before sending either one.
- SIGPIPE (13) — "the pipe you were writing to closed." The cause when commands die mid-pipeline.
Catching signals in scripts: trap
trap 'echo "caught Ctrl+C"; cleanup; exit 130' INT
trap 'rm -f /tmp/lock' EXIT
trap '' HUP # ignore SIGHUP for this scriptAn EXIT trap centralizes cleanup for shell exits the process can handle. It cannot run after SIGKILL, power loss, or a kernel failure, so cleanup must be safe to repeat and stale state must be recoverable.
watch — repeat a command
watch -n 1 'ls -lah | head' reruns every 1 second and displays the latest output, highlighting changes. Perfect for monitoring queue size, log line count, file growth. macOS doesn't ship watch — brew install watch.
watch flags
-n 5— interval in seconds.-d— highlight differences from the previous output.-c— interpret ANSI colors in the output.-x— execute command verbatim instead of via shell (needed for some quoting cases).
The minimum-viable monitor
watch -n 2 -d 'ls -lh /var/log/build.log'Run during a long build. Size and timestamp tick; you know it's alive without flooding your screen with tail -f.
Use signal names instead of numbers
Not every signal number is portable. Write -TERM and -HUP in scripts and documentation, and inspect kill -l on the target machine.
watch is only an observation loop
Repeating an expensive command too quickly can add load to a failing system. Measure one run and choose an interval that fits the rate of change. Recovery and alerts require a monitoring owner beyond a watch screen.