在初始化/bash脚本中同时执行多个程序 [英] Execute several programs at the same time in an initialisation/bash script

查看:54
本文介绍了在初始化/bash脚本中同时执行多个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

我要同时运行所有测试,并且仅在所有先前测试完成后才执行exit命令.不仅在测试4完成后,这还可以吗?谢谢.

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.

推荐答案

您可以使用wait:

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

在bash手册页中:

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

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.

这篇关于在初始化/bash脚本中同时执行多个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆