Sorry. I mean: for (( i=0; i<32; i++ )); do exit $i & done; for (( i=0; i<32; i++ )); do wait -n; echo $?; done;
doesn't function. With an ampersand instead of a semicolon. Why does it function when called from a script and why does it fail when called from the command line? On Mon, Mar 11, 2024 at 7:46 PM Mischa Baars <mjbaars1977.bac...@gmail.com> wrote: > You mean: > > for (( i=0; i<32; i++ )); do exit $i & wait -n; echo $?; done; > > with one command and one wait in a single loop. And this does execute on > the command line. How interesting! > > for (( i=0; i<32; i++ )); do exit $i; done; for (( i=0; i<32; i++ )); do > wait -n; echo $?; done; > > Because this doesn't and to be honest, I needed the pid and its index to > retrieve gcc's output from a log file array afterwards. > > On Mon, Mar 11, 2024 at 7:25 PM alex xmb sw ratchev <fxmb...@gmail.com> > wrote: > >> >> >> On Mon, Mar 11, 2024, 19:22 Mischa Baars <mjbaars1977.bac...@gmail.com> >> wrote: >> >>> On Mon, Mar 11, 2024 at 6:22 PM alex xmb sw ratchev <fxmb...@gmail.com> >>> wrote: >>> >>>> i also completly dont get ur issue >>>> >>>> f=( a.c b.c .. ) threads=$( nproc ) i=-1 r= >>>> >>>> while [[ -v f[++i] ]] ; do >>>> (( ++r > threads )) && >>>> wait -n >>>> gcc -c "${f[i]}" & >>>> done >>>> >>> >>> How nice! >>> >>> wait -n exit 1 & echo $? >>> >> >> doesnt need a pid >> 1 : 1 as i wrote it , excepts add 'wait' as new last line >> >> You got me the solution :) Except that wait expects a pid after -n. >>> >>> Maybe >>> >>> for (( i=0; i<32; i++ )); do exit 1 & wait -n $!; echo $?; done; >>> >>> is what you meant? The equivalence of sequential execution? >>> >>> First think, then do magic. >>> >>> >>>> >>>> >>> >>>> >>>> On Mon, Mar 11, 2024, 18:16 Mischa Baars <mjbaars1977.bac...@gmail.com> >>>> wrote: >>>> >>>>> Hello Paul, >>>>> >>>>> It seems I'm awake a little longer than you are. >>>>> >>>>> The second paragraph as you see it, belongs to 1) >>>>> The fourth paragraph as you see it, belongs to 2) >>>>> >>>>> The actual command invocations (a Makefile, a make.sh script) can be >>>>> found >>>>> in the attachment, as indicated on the first line of the mail. In the >>>>> attachment there are two directories, one and two, belonging to 1) and >>>>> 2) >>>>> respectively. >>>>> >>>>> I'm not into Vulcan mindmelds, so I hope everything from the first mail >>>>> makes sense to you and everyone on this mailing list now. >>>>> >>>>> Best regards, >>>>> Mischa Baars. >>>>> >>>>> On Mon, Mar 11, 2024 at 5:01 PM Paul Smith <psm...@gnu.org> wrote: >>>>> >>>>> > On Mon, 2024-03-11 at 09:56 +0100, Mischa Baars wrote: >>>>> > > I've attached the problem. It consists of two parts: >>>>> > > >>>>> > > 1) multi-threaded bash script and / or multi-threaded Makefile >>>>> > > >>>>> > > Running bash script functions as expected, but executing the same >>>>> > > line of code with make and / or the command line, does not >>>>> function. >>>>> > > Perhaps someone could explain to me why? >>>>> > > >>>>> > > 2) passing a string argument from a bash script and / or Makefile >>>>> to >>>>> > > the gcc -D option >>>>> > > >>>>> > > Running the makefile functions as expected, but I have not been >>>>> able >>>>> > > to get similar code to work from a bash script. Can someone please >>>>> > > explain to me what I'm doing wrong? >>>>> > >>>>> > I don't understand the problem. In the third paragraph above you say >>>>> > the bash script works as expected and the makefile doesn't work, but >>>>> in >>>>> > the last paragraph you say that the makefile works as expected but >>>>> you >>>>> > can't get it to work in bash. >>>>> > >>>>> > Please provide actual command invocations (cut and pasted) showing >>>>> the >>>>> > output you received and explaining exactly what is wrong with it. >>>>> > >>>>> > But before you do that, be aware that make does NOT invoke /bin/bash >>>>> as >>>>> > its shell. It invokes /bin/sh. On some systems /bin/sh is actually >>>>> an >>>>> > alias for bash. On other systems it isn't. >>>>> > >>>>> > If you want your makefile to always use bash as its shell, you should >>>>> > add an explicit: >>>>> > >>>>> > SHELL := /bin/bash >>>>> > >>>>> > to your makefile to force it. Maybe that will solve your problem. >>>>> If >>>>> > not we'll need details such as I mention above. >>>>> > >>>>> >>>>