Sometimes I perform some parameter studies with bash. Having four cores, it would be a shame to only use one of them. One could just background all processes, and let the OS manage it. This will result in bad performance.
It would be wiser to at all times allow at most four scripts to run simultaneously. Bash does not provide such facility. Hence, below is a script which can be sourced.
The script allows tuning the MAX_NPROC parameter, the maximum number of simultaneous scripts.
Available functions are
- new_job (for regular commands with pipes and stuff),
- new_job_f (for internal functions),
- wait_jobs (wait for completion) and
- kill_jobs (kill all running jobs).
Download ppool.sh, or click the view more link to view the contents.