陷阱期间SIGTERM未报告为143

时间:2018-04-04 03:03:24

标签: bash shell sigterm

#!/bin/sh

echo "Running $(basename $0) $*"

function on_err {
echo $?
echo "error happened"

}


trap "on_err" 2 15
while true
do
:
done

$ kill -15 pid

给出

0
error happened

我希望看到

143
error happened

1 个答案:

答案 0 :(得分:1)

在while循环中执行某些操作而不是旋转无限。

while true
do
 sleep 1
done

使用kill -15 -PID代替kill -15 PID

<强>输出:

Running test.sh 
0
Terminated: 15
143
相关问题