像這樣的腳本:
exec &> >(tee -a ./test_tee.log)
ping $1
當腳本在 bash 7603 中執行時,exec 行將建立一個名為 13069 的進程,如下所示:
root 13068 7603 0 17:15 pts/5 00:00:00 bash
root 13069 13068 0 17:15 pts/5 00:00:00 bash // where does it come from
root 13070 13068 0 17:15 pts/5 00:00:00 ping google.com
root 13071 13069 0 17:15 pts/5 00:00:00 tee -a ./test_tee.log
我在bash中執行pid 7603的腳本,pid 13068是腳本,為什麼有pid 13069
答案1
附加進程是一個正在執行的子 shell tee -a ./test_tee.log
。用 確認這一點pstree -p | grep -B 1 '[t]ee'
。
你可以告訴這個子shell代替本身與tee
.將相關行更改為:
exec &> >(exec tee -a ./test_tee.log)