获得后台进程返回值
我们用“&”把进程放入后台以后,如果需要了解进程的执行情况,可以使用wait函数。默认情况下wait会等待任意子进程结束但是不会返回子进程的返回值。而以子进程的pid作为参数调用wait时,wait便能够返回该子进程的退出状态了。

#!/bin/bash
dir=`dirname $0`
$dir/test01.sh &
$dir/test02.sh &
echo '' > $dir/tmp.log
for pid in $(jobs -p)
do
wait $pid
status=$?
if [ $status != 0 ];then
echo "$pid status is $status have some error!" >> $dir/tmp.log
else 
echo "$pid status is $status success!" >> $dir/tmp.log
fi
done

 

相关文章:

  • 2022-01-25
  • 2022-12-23
  • 2021-12-06
  • 2021-07-03
  • 2021-10-02
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
相关资源
相似解决方案