trap-event

Bash trap USR2

Second application-defined signal. Its purpose depends on the receiver; repeated signals need not be queued individually. This fixture sends the signal only to its own disposable Bash process using BASHPID. The handler returns, allowing the script to continue. Signals ignored on shell entry may not be trappable in noninteractive Bash. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): handled USR2; continued.

Formal Syntax & Structure

bash syntaxbash
trap 'handler' USR2

Parameters & Attributes

NameTypeDescription
handlershell codeTrusted code executed on delivery.

Return Value

exit status

trap reports registration status; handler execution and subsequent command status are distinct.

Working Example

Example Snippetbash
handler() { printf 'handled USR2\n'; }trap handler USR2 || exit 1kill -USR2 "$BASHPID" || exit 1printf 'continued\n'
Bash Reference