Before capturing signals, you must first understand how to use kill:
Kill-l view Signal
650) this. width = 650; "title =" kill-l.jpg "src =" http://www.bkjia.com/uploads/allimg/131227/2315524596-0.jpg "alt =" 225340553.jpg"/>
Usage:
Kill-NUMBER pid
Kill-SIGKILL pid
Kill-KILL pid
Main signal:
1: SIGHUP ---- repeat the configuration of a process without restarting it and make the new configuration take effect.
2: SIGINT ---- terminate, suspend
9: SIGKILL --- killing a process
15: SIGTERM --- terminate a process
Use of signal capturing:
Usgage:
Trap 'command1; command2; ...... 'Signal
Used at the beginning of the script
In the script, trap can capture signals, but 9 and 15 cannot.
Script: When the script is executed, the fuck is displayed when the termination signal is sent ..
#! /Bin/bash
#
Trap 'echo "fuck..." 'INT
For in 'seq 1 100'
Do
Echo $ I
Sleep 1
Done
Execution result:
This article is from the keepalive blog, please be sure to keep this source http://jefferyyu.blog.51cto.com/2843635/1302944