bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multi-threaded compiling


From: Mischa Baars
Subject: Re: multi-threaded compiling
Date: Mon, 11 Mar 2024 20:51:39 +0100

On Mon, 11 Mar 2024, 20:36 Greg Wooledge, <greg@wooledge.org> wrote:

> > On Mon, Mar 11, 2024, 20:13 Mischa Baars <mjbaars1977.backup@gmail.com>
> > wrote:
> >
> > > Also I don't think that gives you an exit status for each 'exit $i'
> > > started. I need that exit status.
>
> "wait -n" without a PID won't help you, then.  You don't get the PID or
> job ID that terminated, and you don't get the exit status.  It's only
> of interest if you're trying to do something like "run these 100 jobs,
> 5 at a time" without storing their exit statuses.
>
> If you need to reap each individual job and store its exit status indexed
> by its PID, then you're probably going to need something like:
>
>
> #!/bin/bash
> i=0 pid=() status=()
> for job in ...; do
>     longrunner "$job" & pid[i++]=$!
> done
>
> for ((i=0; i < ${#pid[@]}; i++)); do
>     wait "${pid[i]}"; status[i]=$#
> done
>
>
> You won't be able to take advantage of "wait -n"'s ability to react
> to the first job that finishes.  You'll end up reaping each job in the
> order they started, not the order they finished.
>

Exactly my thought, but does that really matter and do we even have another
option?

The glibc wait(2) returns a pid to that purpose. This bash wait doesn't.

>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]