Parallel
Allow to run command with different parameters simultaneously on CPU available
Require parallel package
Quick view
Run echo and sleep under 4 cores
parallel -j4 sleep {}\; echo {} ::: 2 1 4 3
Semaphore
In case you do not want to run your command as one, it is possible to use semaphore
sem # equivalent to parallel --semaphore
sem --jobs 2 --id id-for-sleep 'sleep 10s; echo "10s done"' # semaphore cannot benefit from :::
sem --jobs 2 --id id-for-sleep sleep 5s\; echo "5s done"
sem --wait --id id-for-sleep; echo "done" # wait all semaphore (commands) are done
Note:
- All options present in
parallelare not necessarily guaranteed to work undersem, such as--joblogwill be overwrite by each command fromsem --idensure your working under the same semaphore (namespace)--jobsneed to be specified each time
Go further
See man parallel which got many examples