为了最大化cpu使用率(我在EC2的Debian Lenny上运行东西)我有一个简单的脚本来并行启动作业:
#!/bin/bash for i in apache-200901*.log; do echo "Processing $i ..."; do_something_important; done & for i in apache-200902*.log; do echo "Processing $i ..."; do_something_important; done & for i in apache-200903*.log; do echo "Processing $i ..."; do_something_important; done & for i in apache-200904*.log; do echo "Processing $i ..."; do_something_important; done & ...
我对这个工作解决方案非常满意,但是我不知道如何编写更多的代码,只有在所有的循环都完成后才执行。
有没有办法控制这个?
有一个bash内置命令。
原文链接:https://www.f2er.com/bash/389090.htmlwait [n ...] Wait for each specified process and return its termination sta‐ tus. 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 pro‐ cesses 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.