[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: multi-threaded compiling
From: |
Kerin Millar |
Subject: |
Re: multi-threaded compiling |
Date: |
Mon, 11 Mar 2024 20:07:53 +0000 |
On Mon, 11 Mar 2024 15:36:48 -0400
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
It does convey the exit status.
> of interest if you're trying to do something like "run these 100 jobs,
> 5 at a time" without storing their exit statuses.
The pid can be obtained with the -p option, as of 5.1. Below is a synthetic
example of how it might be put into practice.
#!/bin/bash
declare -A job_by status_by
max_jobs=4
jobs=0
wait_next() {
local pid
wait -n -p pid
status_by[$pid]=$?
unset -v 'job_by[$pid]'
}
worker() {
sleep "$(( RANDOM % 5 ))"
exit "$(( RANDOM % 2 ))"
}
for (( i = 0; i < 16; ++i )); do
(( jobs++ < max_jobs )) || wait_next
worker & job_by[$!]=
done
while (( ${#job_by[@]} )); do
wait_next
done
declare -p status_by
--
Kerin Millar
- Re: multi-threaded compiling, (continued)
- Re: multi-threaded compiling, Mischa Baars, 2024/03/12
- Re: multi-threaded compiling, Mischa Baars, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, Mischa Baars, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, Greg Wooledge, 2024/03/11
- Re: multi-threaded compiling, Paul Smith, 2024/03/11
- Re: multi-threaded compiling, Mischa Baars, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling,
Kerin Millar <=
- Re: multi-threaded compiling, Mischa Baars, 2024/03/11
- Re: multi-threaded compiling, Greg Wooledge, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, alex xmb sw ratchev, 2024/03/11
- Re: multi-threaded compiling, Chet Ramey, 2024/03/11
- Re: multi-threaded compiling, Mischa Baars, 2024/03/11
- Re: multi-threaded compiling, Greg Wooledge, 2024/03/11