1
我試圖做一個腳本,將參數上運行一個程序。 程序執行1分鐘後程序將退出。Bash腳本啓動程序,並在給定的時間退出
我的代碼如下所示:
pid=$(pidof $1)
true=1
$1
while [ $true = 1 ]
do
time=$(ps -p $pid -o etime=)
if $time > 01:00
then
true=0
kill -9 $pid
echo "The process $pid has finish since the execution time has ended"
fi
done
任何想法?程序午餐但不退出。
真的沒有在bash中執行$ true檢查(':'爲true)的原因。只要做'while:';做',並在if塊結束時打破或退出。 – BroSlow
使用一個簡單的'kill'而不是'kill -9',讓這個過程有機會在退出之前自行清理。 – chepner