【问题标题】:SIGTERM not reported as 143 during trap陷阱期间 SIGTERM 未报告为 143
【发布时间】:2018-09-13 11:42:40
【问题描述】:
#!/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

【问题讨论】:

    标签: bash shell sigterm


    【解决方案1】:

    在 while 循环中做一些事情,而不是无限旋转。

    while true
    do
     sleep 1
    done
    

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

    输出:

    Running test.sh 
    0
    Terminated: 15
    143
    

    【讨论】:

    • 这有什么关系?
    • 为什么要在while循环中做某事?
    • 这是来自 bash 手册页:if bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多