所以说我有类似的东西:
#!/bin/bash
testfunc(){
echo "blah"
sleep 30
}
for blah in blahs; do
testfunc &
done
wait
我的脚本在bg中调用了一堆我的函数,等待它们全部完成没有问题......但我需要做的是从脚本的开头开始另一个函数,并且一直运行到我等待之后,然后结束。
#!/bin/bash
testfunc(){
echo "blah"
sleep 30
}
gatherloadavg(){
while true; do
echo "my load averages and other performance data I want" >> blah.txt
done
}
gatherloadavg &
for blah in blahs; do
testfunc &
done
wait
答案 0 :(得分:2)
wait
接受一个可选的PID列表。所以你应该能够做到这样的事情:
gatherloadavg &
statspid=$!
for blah in blahs; do
testfunc &
pidlist="$pidlist $!"
done
wait $pidlist
kill $statspid