16.2信号捕捉
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了16.2信号捕捉相关的知识,希望对你有一定的参考价值。
1、信号帮助:方法一:#man 7 signal
方法二:#kill -l
方法三:#trap -l
2、常用信号列表
Signal Value Action Comment ────────────────────────────────────────────────────────────────────── SIGHUP 1 Term Hangup detected on controlling terminal or death of controlling process SIGINT 2 Term Interrupt from keyboard SIGQUIT 3 Core Quit from keyboard SIGILL 4 Core Illegal Instruction SIGABRT 6 Core Abort signal from abort(3) SIGFPE 8 Core Floating point exception SIGKILL 9 Term Kill signal SIGSEGV 11 Core Invalid memory reference SIGPIPE 13 Term Broken pipe: write to pipe with no readers SIGALRM 14 Term Timer signal from alarm(2) SIGTERM 15 Term Termination signal SIGUSR1 30,10,16 Term User-defined signal 1 SIGUSR2 31,12,17 Term User-defined signal 2 SIGCHLD 20,17,18 Ign Child stopped or terminated SIGCONT 19,18,25 Cont Continue if stopped SIGSTOP 17,19,23 Stop Stop process SIGTSTP 18,20,24 Stop Stop typed at terminal SIGTTIN 21,21,26 Stop Terminal input for background process SIGTTOU 22,22,27 Stop Terminal output for background process |
3、trap:捕捉信号,
它不能捕捉9号信号(SIGKILL)和15号信号(SIGTERM),一般常用的捕捉信号是HUP和INT信号。
可以自定义捕捉信号后的处理方法
4、trap命令用法:
格式:trap 'command ' signal //command为捕捉信号后要执行的命令或脚本或函数,多个命令之间用分号(;)隔开;signal为要捕捉的信号
示例1:
[[email protected] sh]# cat tr.sh
#!/bin/bash
trap 'echo "quit";exit' INT //一般把trap写在最上面,多个command之间用分号(;)隔开,
for i in {1..10};do
ping -W 1 -c 1 192.168.0.$i
done
[[email protected] sh]#
示例二:
以上是关于16.2信号捕捉的主要内容,如果未能解决你的问题,请参考以下文章