我可以使用脚本测试键盘快捷键和一些kill
命令并知道哪个信号被捕获吗trap
?
答案1
使用此脚本,您可以测试所有信号:
#!/bin/sh
# Know which signal is caught
# man 7 signal
trap "echo 'SIGHUP 1 Term Hangup (disconnection) or control process termination.'" 1
trap "echo 'SIGINT 2 Term Interrupt from keyboard.'" 2
trap "echo 'SIGQUIT 3 Core Quit request from keyboard.'" 3
trap "echo 'SIGILL 4 Core Illegal instruction.'" 4
trap "echo 'signal 5 not referenced'" 5
trap "echo 'SIGABRT 6 Core Abort signal from abort(3).'" 6
trap "echo 'signal 7 not referenced'" 7
trap "echo 'SIGFPE 8 Core Floating point arithmetic error.'" 8
trap "echo 'signal 10 not referenced'" 10
trap "echo 'SIGSEGV 11 Core Invalid memory reference.'" 11
trap "echo 'signal 12 not referenced'" 12
trap "echo 'SIGPIPE 13 Term Write on a pipe with no reader.'" 13
trap "echo 'SIGALRM 14 Term Alarm clock signal (used by alarm(2)).'" 14
trap "echo 'SIGTERM 15 Term Termination signal.'" 15
trap "echo 'SIGUSR1 30,10,16 Term User-defined signal 1.'" 30 10 16
trap "echo 'SIGUSR2 31,12,17 Term User-defined signal 2.'" 31 12 17
trap "echo 'SIGCHLD 20,17,18 Ign Child stopped or terminated.'" 20 17 18
trap "echo 'SIGCONT 19,18,25 Cont Continue if stopped.'" 19 18 25
trap "echo 'SIGTSTP 18,20,24 Stop Stop signal generated from keyboard.'" 18 20 24
trap "echo 'SIGTTIN 21,21,26 Stop Background process attempting to read from tty.'" 21 21 26
trap "echo 'SIGTTOU 22,22,27 Stop Background process attempting to write to tty.'" 22 22 27
trap "echo 'SIGWINCH 28,28,20 Ign Window resize signal (4.3 BSD, Sun).'" 28 20
read _
这些信号SIGKILL
无法SIGSTOP
被捕获、阻止或忽略。 ( 9
, 19
)。
和http://mywiki.wooledge.org/SignalTrap
为避免复制/粘贴:
wget -O signal-finder.sh https://gist.githubusercontent.com/sputnick-dev/7260ac0aa46f067f469ee8184b69acb3/raw/4286bcda6d3353aad7584ab320048af4d8bfa197/gistfile1.txt
chmod +x signal-finder.sh
./signal-finder.sh