Bash文件:并行运行进程,并在进程结束时停止 [英] Bash files: run process in parallel and stop when one is over

查看:67
本文介绍了Bash文件:并行运行进程,并在进程结束时停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从bash文件中并行启动两个C代码,第二个在第一个完成时停止.等待指令会导致两个进程都停止,这不是我想要做的.感谢您的任何建议.

I would like to start two C codes from a bash file in parallel and the second one stops when the first one has finished. The instruction wait expects both processes to stop which is not what I would like to do. Thanks for any suggestion.

推荐答案

GNU并行可以做这种工作.检查终止部分,它可以根据退出关闭其余进程代码(成功或失败:

GNU parallel can do this kind of job. Check termination section, it can shutdown down remaining processes based on the exit code (either success or failure:

parallel -j2 --halt now,success=1 ::: 'cmd1 args' 'cmd2 args'

其中一个作业成功完成时,它将向其他作业发送TERM信号(如果作业未终止,则使用KILL信号强制执行该操作).

When one of the job finishes successfully, it will send TERM signal to the other jobs (if jobs are not terminated it forces using KILL signal).

这篇关于Bash文件:并行运行进程,并在进程结束时停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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