首页 > 解决方案 > 如果在同一个陷阱处理程序中触发信号会发生什么?

问题描述

假设我有以下 bash

chld_handler() {
    trap '' CHLD # ignore while we handle
    echo "$(date)" # this won't trigger chld now
    trap 'chld_handler' CHLD # restore
}

# I want to be notified of the exit of any of these processes
xterm &
xterm &
xterm &

trap 'chld_handler' CHLD # first time setup

如果其中一个作业进程退出,chld_handler被调用并且当处理程序运行另一个作业进程退出时会发生什么?第二个CHLD信号会排队吗?

标签: linuxbash

解决方案


推荐阅读