Database Reference
In-Depth Information
[3] 3336
[4] 3338
Starting job 2
Starting job 1
Starting job 3
Starting job 4
Job 4 took 1 seconds
Processed 4
Job 3 took 4 seconds
Job 2 took 4 seconds
Processed 3
Processed 2
Job 1 took 4 seconds
Processed 1
Parentheses create a subshell. The ampersand ( & ) ensures that it will be executed
in the background.
The problem with subshells is that they are executed all at once. There is no mecha‐
nism to control the maximum number of processes. You are not advised to use this:
$ while read i; do
> ( ./slow.sh "$i" ; ) &
> done < data/movies.txt
[1] 3404
[2] 3405
[3] 3406
Starting job Star Wars
Starting job Matrix
Starting job Home Alone
[4] 3407
[5] 3410
Starting job Back to the Future
Starting job Indiana Jones
Job Home Alone took 2 seconds
Job Matrix took 2 seconds
Job Star Wars took 2 seconds
Job Back to the Future took 3 seconds
Job Indiana Jones took 4 seconds
Not everything can be parallelized: API calls may be limited to a
certain number, or some commands can only have one instance.
Quoting is important. If we did not quote $i , then only the first
word of each movie would have been passed to the script slow.sh .
Search WWH ::




Custom Search