Wait for bash background jobs in script to be finished

后端 未结 4 1670
抹茶落季
抹茶落季 2020-12-05 03:53

To maximize CPU usage (I run things on a Debian Lenny in EC2) I have a simple script to launch jobs in parallel:

#!/bin/bash

for i in apache-200901*.log; do         


        
4条回答
  •  既然无缘
    2020-12-05 04:36

    There's a bash builtin command for that.

    wait [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.
    

提交回复
热议问题