在Shell脚本中使用Trap捕获相关信号进行hook
2010-08-24 10:38
579 查看
from http://steve-parker.org/sh/trap.shtml
trap指令可以用来捕获相关信号,并运行指定的代码
例如
#!/bin/sh
trap cleanup EXIT
#or
#trap cleanup 0
cleanup()
{
#do some cleanup thing when exit
#...
}
或者
trap handle_interrupt 2
handle_interrupt()
{
#do sth when ctrl_c is pressed
#...
}
下面是一些常见信号的数值
trap指令可以用来捕获相关信号,并运行指定的代码
例如
#!/bin/sh
trap cleanup EXIT
#or
#trap cleanup 0
cleanup()
{
#do some cleanup thing when exit
#...
}
或者
trap handle_interrupt 2
handle_interrupt()
{
#do sth when ctrl_c is pressed
#...
}
下面是一些常见信号的数值
0 | 0 | On exit from shell |
1 | SIGHUP | Clean tidyup |
2 | SIGINT | Interrupt |
3 | SIGQUIT | Quit |
6 | SIGABRT | Abort |
9 | SIGKILL | Die Now (cannot be trap'ped) |
14 | SIGALRM | Alarm Clock |
15 | SIGTERM | Terminate |
相关文章推荐
- 老男孩教育每日一题-第69天-shell脚本知识点:linux系统脚本中trap信号都有哪些,如何进行使用?
- 使用trap/tee命令/调试钩子调试Shell脚本
- linux使用svn update进行shell脚本提示用户密码
- 使用shell脚本进行服务器系统监控——文件系统监控(5)
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用shell 脚本对 Linux 系统进程的CPU使用率与内存资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用shell脚本进行服务器系统监控——系统负载监控(4)
- Linux下shell脚本中信号捕获和函数练习脚本之ping一个网段
- 使用shell脚本进行服务器系统监控——文件系统监控(2)
- 使用Shell脚本对Linux系统和进程资源进行监控
- 使用Shell脚本对Linux系统和进程资源进行监控(转)
- trap在shell脚本中捕捉信号的方法.
- shell学习五十三天----捕获信号trap
- 使用 shell 脚本对 Linux 系统和进程资源进行监控
- 使用shell脚本进行服务器系统监控——文件系统监控(3)
- shell脚本和case 使用相关的例子
- 使用shell脚本进行系统备份
- 使用shell脚本进行服务器系统监控——页面调度与交换空间监控
- Shell 脚本基础 - 使用 if 语句进行条件检测