Gilles Quénot Asked: 2023-04-22 09:44:35 +0800 CST2023-04-22 09:44:35 +0800 CST 2023-04-22 09:44:35 +0800 CST 如何跟踪“陷阱”中的所有信号? 772 我可以用脚本测试键盘快捷键和一些kill命令并知道捕获了哪个信号吗trap? shell 1 个回答 Voted Best Answer Gilles Quénot 2023-04-22T09:44:35+08:002023-04-22T09:44:35+08:00 使用此脚本,您可以测试所有信号: #!/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)。 见man 7 signal 和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
使用此脚本,您可以测试所有信号:
信号
SIGKILL
和SIGSTOP
不能被捕获、阻止或忽略。(9
,19
)。见man 7 signal
和http://mywiki.wooledge.org/SignalTrap
为避免复制/粘贴: