Bash unix signals: Difference between revisions
From wikinotes
Line 9: | Line 9: | ||
|} | |} | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
= Signal Keybindings = | |||
<blockquote> | |||
List signal keybindings | |||
<syntaxhighlight lang="bash"> | |||
stty -a | tr ';' '\n' | |||
# intr = ^C | |||
# quit = ^\ | |||
# erase = ^? | |||
# ... | |||
</syntaxhighlight> | |||
</blockquote><!-- Signal Keybindings --> | |||
= Send Signal = | = Send Signal = |
Revision as of 14:51, 17 December 2022
Documentation
man 7 signal
https://man.archlinux.org/man/core/man-pages/signal.7.en wikipedia: unix signals https://en.wikipedia.org/wiki/Signal_(IPC)#POSIX_signals
Signal Keybindings
List signal keybindings
stty -a | tr ';' '\n' # intr = ^C # quit = ^\ # erase = ^? # ...
Send Signal
kill -l # list all signals kill -9 ${PID} # send signal 9 (SIGKILL) kill -SIGINT ${PID} # send isgnal 2 (SIGINT)
Callback on Signal
# Install callback for SIGINT and SIGTRAP on_signal() { echo "received SIGINT or SIGTRAP!" } trap on_signal SIGINT SIGTRAP # Uninstall a trap trap - SIGINT SIGTRAPYou can also trap on any process error (and implement behaviour similar to
set -e
)on_error() { echo "There was an error on line $LINENO" exit 1 } trap on_error ERR