我有一个脚本在后台启动另一个脚本,然后终止它。我原以为子脚本会消失,但最后它仍然设法打印一些输出。这是示例:
在脚本 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终止,所以“这是三”不应该出现在输出中吗?您能否向我指出任何描述进程在(非)后台时的行为以及它们终止时会发生什么的文档?
非常感谢您的帮助!