小编dic*_*tto的帖子

陷阱和 SIGINT 的奇怪问题

请解释一下:

#!/bin/bash
# This is scripta.sh
./scriptb.sh &
pid=$!
echo $pid started
sleep 3
while true
do
    kill -SIGINT $pid
    echo scripta.sh $$
    sleep 3
done 
Run Code Online (Sandbox Code Playgroud)

——

#!/bin/bash
# This is scriptb.sh
trap "echo Ouch;" SIGINT

while true
do
 echo scriptb.sh $$
 sleep 1
done
Run Code Online (Sandbox Code Playgroud)

当我运行./scripta.sh陷阱不打印。如果我从 SIGINT 切换到任何其他信号(我尝试了 SIGTERM、SIGUSR1),陷阱会按预期打印“哎哟”。这怎么会发生?

shell bash signals trap background-process

6
推荐指数
2
解决办法
3672
查看次数

标签 统计

background-process ×1

bash ×1

shell ×1

signals ×1

trap ×1