在初始化/bash 脚本中同时执行多个程序

发布于 2024-07-10 18:34:12 字数 206 浏览 4 评论 0原文

您好,我正在使用一个使用 rcS 脚本启动的模拟器,这是我的脚本

cd /tests
./test1 &
./test2 &
./test3 &
./test4 
exit

我想要的是同时运行所有测试,并且仅当所有先前的测试完成时才执行退出命令。 而且不仅是当测试 4 完成后,这可能吗? 谢谢。

Hello I am working with a simulator that uses rcS scripts to boot, this is my script

cd /tests
./test1 &
./test2 &
./test3 &
./test4 
exit

What I want is run all the test at the same time and that the exit command is executed only when all the previous test have finished. And not only when test 4 has finished, is this possible?.
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世界等同你 2024-07-17 18:34:12

您可以使用 wait:

./test1 &
./test2 &
./test3 &
./test4 &
wait

从 bash 手册页:

等等[n ...]
等待每个指定的进程并返回其
终止状态。 每个n可以是一个
进程 ID 或作业规范; 如果
给出了工作规范,所有流程都在
该作业的管道正在等待。
如果未给出 n,
等待所有当前活动的子进程,并且
返回状态为零。 如果 n
指定一个不存在的进程或
作业,返回状态为127。
否则,返回状态为
最后的退出状态
等待的进程或作业。

You can use wait:

./test1 &
./test2 &
./test3 &
./test4 &
wait

From the bash man page:

wait [n ...]
Wait for each specified process and return its
termination status. Each n may be a
process ID or a job specification; if
a job spec is given, all processes in
that job's pipeline are waited for.
If n is not given,
all currently active child processes are waited for, and
the return status is zero. If n
specifies a non-existent process or
job, the return status is 127.
Otherwise, the return status is the
exit status of the last
process or job waited for.

哆兒滾 2024-07-17 18:34:12

xargs 可以支持并行

所以就像这样:

seq 4|xargs -i -n 1 -P 4 ./test{} 

xargs can support parallel

So just like this:

seq 4|xargs -i -n 1 -P 4 ./test{} 
糖果控 2024-07-17 18:34:12

类似的东西

cd /tests
./test1 &
./test2 &
./test3 &
./test4 &
wait
exit

(我假设是 bash shell)

Something along the lines of

cd /tests
./test1 &
./test2 &
./test3 &
./test4 &
wait
exit

(I am assuming bash shell)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文