信号 | 值 | 描述 |
1 | SIGHUP | 挂起进程 |
2 | SIGINT | 中断进程 |
3 | SIGQUIT | 停止进程 |
9 | SIGKILL | 无条件终止进程 |
15 | SIGTERM | 如果可能的话终止进程 |
17 | SIGSTOP | 无条件停止,但不终止进程 |
18 | SIGTSTP | 停止或暂停进程,但不终止它 |
19 | SIGCONT | 重新启动停止的进程 |
$ sh trap.sh
hello
hello
^Z # Ctrl + Z 发出 SIGTSTP 信号
[1]+ Stopped sh trap.sh
$ jobs
[1]+ Stopped sh trap.sh
$ ps au
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
... ... ... ...
beyes 3606 0.0 0.1 5024 1116 pts/0 T 10:41 0:00 sh trap.sh
... ... ... ...
#!/bin/bash
function crcl {
echo "execute a function"
}
trap 'crcl;echo "It is ok"' SIGINT SIGTERM
count=1
while [ $count -le 5 ]
do
echo "$count"
sleep 10
count=$[ $count + 1 ]
done
echo "End of the program"
#!/bin/bash
function crcl {
echo "execute a function"
}
trap 'crcl;echo "It is ok"' SIGINT SIGTERM
count=1
while [ $count -le 10 ]
do
echo "$count"
sleep 10
count=$[ $count + 1 ]
if [ $count -eq 5 ]; then
trap - SIGINT SIGTERM
fi
done
echo "End of the program"
[beyes@SLinux shell]$ sh trap.sh
1
^Cexecute a function
It is ok
2
^Cexecute a function
It is ok
3
^Cexecute a function
It is ok
4
^Cexecute a function
It is ok
5
^C
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |