Pcornel
Linux · Shell & Bash

Signals

Cheat sheet · https://pcornel.dk/topic.php?topic=2696

Back to the Topic

Answer

Signals are notifications the kernel sends to processes: SIGINT (2, Ctrl+C), SIGTERM (15, polite stop), SIGKILL (9, cannot be caught), SIGHUP (1, hangup/reload), SIGSTOP/SIGTSTP (pause) and SIGCONT. kill sends them.

Remember

Send SIGTERM first and give the process time to clean up; use SIGKILL only if it hangs. A process stuck in D state (uninterruptible I/O) ignores even SIGKILL until the I/O finishes. Scripts can catch signals with trap.

First checks

  • kill -l — list signal names and numbers
  • ps -o pid,stat,cmd -p <pid> — process state
  • bash -x script.sh — trace each expanded command
  • bash -n script.sh — syntax check only
  • shellcheck script.sh — common bugs and quoting problems
  • echo $? — exit code of the last command

Commands

systemctl kill -s USR1 <unit>

Verify in this order

signal sent (kill, keyboard, kernel) → delivered → process handler runs or default action (terminate, stop, ignore)

Where it usually breaks

First mismatch in persistent intent → provider/parser/generator → kernel/userspace runtime → dependency/security context → logs/counters → consumer-visible read-back; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2696

Confirmation

Confirm action

Continue?