【问题标题】:multiple command prioritization in bash [duplicate]bash中的多个命令优先级[重复]
【发布时间】:2013-01-20 07:09:18
【问题描述】:

可能重复:
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 进程3

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

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

#!/bin/sh

    (
      process1 &
      process2 &

      wait

      process3

                )

谢谢

法比奥

【问题讨论】:

  • 这会做你想要的。您不需要 ( ) 构造。

标签: bash process wait


【解决方案1】:

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

#!/bin/bash

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

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

process3

【讨论】:

  • 所以您认为单次等待没有任何意义?
  • 它也可以。这只是我的习惯,我认为这更好,因为如果你愿意,你可以检查进程的返回值
  • 知道了!谢谢你们。法比奥
猜你喜欢
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-06
相关资源
最近更新 更多