スクリプトは次のようになります:
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
私は pid 7603 bash でスクリプトを実行しました。pid 13068 はスクリプトです。なぜ pid 13069 があるのでしょうか。
答え1
追加プロセスは を実行するサブシェルですtee -a ./test_tee.log
。 でこれを確認しますpstree -p | grep -B 1 '[t]ee'
。
このサブシェルに交換する自身を にtee
変更します。関連する行を次のように変更します。
exec &> >(exec tee -a ./test_tee.log)