Gentoo Archives: gentoo-user

From: Laurence Perkins <lperkins@×××××××.net>
To: "gentoo-user@l.g.o" <gentoo-user@l.g.o>
Subject: RE: [gentoo-user] Any way to run multiple commands from single script in parallel?
Date: Mon, 14 Mar 2022 17:26:12
Message-Id: DM5PR07MB40550CEE2372528C00F34015D20F9@DM5PR07MB4055.namprd07.prod.outlook.com
In Reply to: Re: [gentoo-user] Any way to run multiple commands from single script in parallel? by Ramon Fischer
1 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.
2
3 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.
4
5 LMP
6
7 -----Original Message-----
8 From: Ramon Fischer <Ramon_Fischer@×××××××.de>
9 Sent: Monday, March 14, 2022 3:37 AM
10 To: gentoo-user@l.g.o
11 Subject: Re: [gentoo-user] Any way to run multiple commands from single script in parallel?
12
13 Hello Joost,
14
15 I suppose, that you are talking about Bash scripts.
16
17 If so, you may put each individual command in a subshell by using an ampersand ("&") at the end of the line.
18
19 This example[1] shows it nicely.
20
21 -Ramon
22
23 [1] 3. Parallelize running commands by grabbing PIDs.:
24 https://will-keleher.com/posts/5-Useful-Bash-Patterns.html
25
26 On 14/03/2022 11:13, J. Roeleveld wrote:
27 > Hi,
28 >
29 > I often put multiple commands into a single file/script to be run in sequence.
30 > (each line can be executed individually, there is no dependency)
31 >
32 > Is there a tool/method to execute multiple lines/commands
33 > simultaneously? Like having 3 or 4 run together and when 1 is
34 > finished, it will grab the next one in the list?
35 >
36 > I would prefer this over simply splitting the file as the different
37 > lines/ commands will not take the same amount of time.
38 >
39 > Thanks,
40 >
41 > Joost
42 >
43 >
44 >
45
46 --
47 GPG public key: 5983 98DA 5F4D A464 38FD CF87 155B E264 13E6 99BF