bash中的多命令优先级

时间:2013-02-05 11:11:12

标签: bash process wait

  

可能重复:
  How to wait in bash for several subprocesses to finish and return exit code !=0 when any subprocess ends with code !=0?

我有以下问题:

我在脚本中放了3个进程

过程1 过程2 process3

我希望进程1和2同时运行,但它们都在进程3开始之前完成。

我想它类似于以下......但我不确定那个“等待”

#!/bin/sh

    (
      process1 &
      process2 &

      wait

      process3

                )

谢谢

的Fabio

1 个答案:

答案 0 :(得分:3)

只需保存两个进程的pid并等待两个进程退出

#!/bin/bash

process1 &
pid1=$!
process2 &
pid2=$!

wait ${pid1}
echo "Return value of process1: $?"
wait ${pid2}
echo "Return value of process2: $?"

process3