Commit 2264ee10 authored by Cooper, Caleb's avatar Cooper, Caleb

Update rse-bash-modules.sh

parent 3d6134de
......@@ -106,3 +106,36 @@ func_rse_info_dump() {
docker ps
export
}
func_rse_parallel() {
declare -i PID=$$
declare ACTION
declare INPUT
declare -i NUM_PROCESSES
while getopts "a:i:n:" OPTION; do
case ${OPTION} in
a)
ACTION="${OPTARG}";;
i)
INPUTS="${OPTARG}";;
n)
NUM_PROCESSES=${OPTARG};;
esac
done
if [[ -z "${ACTION}" ]] || [[ -z "${INPUTS}" ]] || [[ -z "${NUM_PROCESSES}" ]]; then
printf "All three flags are required:\n\t-a) The action to be executed by each process.\n\t-i) The input list from which new processes will pull data.\n\t-n) Number of parallel processes.\n"
exit 1
fi
declare -a INPUTS_ARRAY=( $(eval "${INPUTS}") )
for INPUT in ${INPUTS_ARRAY[*]}; do
mapfile -t CHILDREN < <(pgrep -P $PID)
while [[ ${#CHILDREN[@]} -gt ${NUM_PROCESSES} ]]; do
read -r -s -t 0.1
mapfile -t CHILDREN < <(pgrep -P $PID)
done
${ACTION} ${INPUT} &
done
wait
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment