If you don't want to do thread management yourself in bash then you can use 
something like GNU Parallel (in the repo) to handle forking and collating 
processes for you.

Parallel in particular has the additional advantage that it's capable of 
shipping tasks off to other machines via SSH, so if you get to the point where 
you need a whole cluster to do your processing it's just a matter of adding a 
couple of arguments.

LMP

-----Original Message-----
From: Ramon Fischer <ramon_fisc...@hotmail.de> 
Sent: Monday, March 14, 2022 3:37 AM
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Any way to run multiple commands from single script 
in parallel?

Hello Joost,

I suppose, that you are talking about Bash scripts.

If so, you may put each individual command in a subshell by using an ampersand 
("&") at the end of the line.

This example[1] shows it nicely.

-Ramon

[1] 3. Parallelize running commands by grabbing PIDs.: 
https://will-keleher.com/posts/5-Useful-Bash-Patterns.html

On 14/03/2022 11:13, J. Roeleveld wrote:
> Hi,
>
> I often put multiple commands into a single file/script to be run in sequence.
> (each line can be executed individually, there is no dependency)
>
> Is there a tool/method to execute multiple lines/commands 
> simultaneously? Like having 3 or 4 run together and when 1 is 
> finished, it will grab the next one in the list?
>
> I would prefer this over simply splitting the file as the different 
> lines/ commands will not take the same amount of time.
>
> Thanks,
>
> Joost
>
>
>

--
GPG public key: 5983 98DA 5F4D A464 38FD CF87 155B E264 13E6 99BF

Reply via email to