我有一個腳本,在後臺啓動另一個腳本,然後終止它。我期待孩子的腳本消失,但最終它仍然設法打印一些輸出。這裏是例子:如何用&(在bash中)製作過程並殺死它們?
腳本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終止?你能不能指出我的任何文檔,這些文檔描述了進程在不在後臺時的行爲以及在終止時會發生什麼?
非常感謝您的幫助!
init進程不會殺死孩子;它僅收集屍體(殭屍)的統計數據,以便殭屍不會無限制地積累。 –
謝謝,我編輯了答案 – kamjagin