我有一個簡單的bash腳本中的所有進程運行給定數量的過程:退出,殼牌開始
#!/bin/bash
# usage: ./run-abt.sh <agent count> <responder port> <publisher port>
echo "./abt-monitor 127.0.0.1 $2 $3 $1"
exec ./abt-monitor 127.0.0.1 $2 $3 $1 &
for ((i=1; i<=$1; i++))
do
echo "Running agent $i";
exec ./abt-agent 127.0.0.1 $2 $3 $i $1 > $i.txt &
done
我需要添加用戶按Ctrl+C
和控制返回到bash中,所有的進程創建的時候是通過run-abt.sh
來殺死。
注意這不會啓動任何代理:執行腳本的bash進程將由abt-monitor進程*替換,因爲執行命令。 [文檔](http://www.gnu.org/software/bash/manual/bashref.html#index-exec) –
該exec發生在由'&'運算符啓動的子shell中。 – chepner