In a Bash script, I would like to do something like:
app1 &
pidApp1=$!
app2 &
pidApp2=$1
timeout 60 wait $pidApp1 $pidApp2
kill -9 $pidApp1 $pidApp2
I.e., launch two applications in the background, and give them 60 seconds to complete their work. Then, if they don't finish within that interval, kill them.
Unfortunately, the above does not work, since timeout
is an executable, while wait
is a shell command. I tried changing it to:
timeout 60 bash -c wait $pidApp1 $pidApp2
But this still does not work, since wait
can only be called on a PID launched within the same shell.
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…