#!/bin/bash
#
# #BINDIR#/runjobsparallel: run all executables in specified directory parallel
# version #VERSION#
#
if [ ! -d "$1" ] || [ $# -ne 1 ]
then
>&2 echo 'runjobsparallel version #VERSION#'
>&2 echo ''
>&2 echo "usage: $0
"
exit 1
fi
cd "$1" || exit 1
tmpDir=$(mktemp -d #TMPDIR#/runjobsparallel.XXXXXX)
for file in ./*; do
if [ -f "${file}" ] && [ -x "${file}" ]; then
i=${#errFiles[@]}
errFiles[${i}]="${tmpDir}/err.${i}"
(
nice -n 19 "${file}"
echo $? > "${errFiles[${i}]}"
)&
pids[${i}]=$!
fi
done
allesDa=false
while ! ${allesDa}
do
sleep 1
allesDa=true
maxErr=0
for ((i=0; i<${#errFiles[@]}; i++))
do
if [ -r "${errFiles[${i}]}" ]; then
curErr=$(cat "${errFiles[${i}]}")
[ ${curErr} -gt ${maxErr} ] && maxErr=${curErr}
elif [ -d "/proc/${pids[${i}]}" ]; then
allesDa=false
else
echo 255 > "${errFiles[${i}]}"
maxErr=255
fi
done
done
rm -rf --one-file-system "${tmpDir}"
exit ${maxErr}
# End of file