【发布时间】:2013-06-28 15:15:45
【问题描述】:
我有一个脚本在后台启动另一个脚本,然后终止它。我原以为子脚本会消失,但最后它仍然设法打印一些输出。示例如下:
在脚本 one.sh 中:
echo "this is one"
./two.sh &
sleep 1
pid=$!
kill $pid
echo "this was one"
在脚本 two.sh 中:
echo "this is two"
./three.sh
echo "this was two"
在脚本three.sh中:
echo "this is three"
sleep 5
echo "this was three"
我运行了 ./one.sh,它应该在后台运行 two.sh,而后者又运行 three.sh 但不在后台!得到的输出是:
this is one
this is two
this is three
this was one
this was three
由于three.sh 没有在后台运行并且two.sh 被one.sh 终止,因此输出中不应该出现“this was three”吗?您能否向我指出任何描述进程在(非)后台时的行为以及终止时会发生什么的文档?
非常感谢您的帮助!
【问题讨论】: