捕获CHLD信号 - ZSH的作品,但KSH /庆典/ sh的不? [英] Trapping CHLD signal - ZSH works but ksh/bash/sh don't?

查看:106
本文介绍了捕获CHLD信号 - ZSH的作品,但KSH /庆典/ sh的不?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个示例code其中一个shell脚本在后台在接收到信号CHLD(即子进程终止),它会采取一些行动,推出一些工作...问题是,如果父shell脚本是一个ZSH之一,它工作得很好,并捕获CHLD信号,但其他贝壳做的的!这是为什么?

 #! /斌/ zsh的 - 函数foo(){回声被困CHLD信号!
}陷阱'富'CHLD./child-work1.sh&安培;
./child-work2.sh&安培;
./child-work3.sh&安培;回声等待孩子们
等待
呼应--------- ---------做


解决方案

猛砸自动启用作业控制时互动,但在脚本,你必须明确地打开它。

 设置-m

Here's a sample code where a shell script launches a few jobs in the background and upon receiving the CHLD signal (i.e. the child process termination) it will take some actions... The problem is that if the parent shell script is a ZSH one, it works just fine and traps the CHLD signals, but other shells do not! why is that?

#! /bin/zsh -

function foo() { echo "Trapped CHLD signal!" 
}   

trap 'foo' CHLD

./child-work1.sh &
./child-work2.sh &
./child-work3.sh &

echo 'waiting for the children'
wait
echo '--------- done ---------'

解决方案

Bash automatically enables job control when interactive, but in scripts you must turn it on explicitly.

set -m

这篇关于捕获CHLD信号 - ZSH的作品,但KSH /庆典/ sh的不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆