gpt4 book ai didi

bash - 从 bash 脚本如何判断进程何时完成

转载 作者:行者123 更新时间:2023-11-29 09:21:33 24 4
gpt4 key购买 nike

我试图在 bash 脚本中启动多个命令,但要等待它们完成

看起来像这样:

A &
B &
C &
D

不幸的是,我不知道这些进程中的哪一个会先完成。但是我需要整个脚本在完成所有进程后才能完成。

所以我像菜鸟一样尝试过:

(A &
B &
C &
D) && E

不幸的是,E 仅在 D 完成后执行。如果我能让 E 在 A - D exec 之后发生,我会很高兴

希望这就是问题所在。

谢谢

最佳答案

A &
B &
C &
D &
wait
E

来自帮助列表:

wait: wait [-n] [id ...]    Wait for job completion and return exit status.    Waits for each process identified by an ID, which may be a process ID or a    job specification, and reports its termination status.  If ID is not    given, waits for all currently active child processes, and the return    status is zero.  If ID is a a job specification, waits for all processes    in that job's pipeline.    If the -n option is supplied, waits for the next job to terminate and    returns its exit status.    Exit Status:    Returns the status of the last ID; fails if ID is invalid or an invalid    option is given.

关于bash - 从 bash 脚本如何判断进程何时完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27927324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com